PowerBI Azure 成本管理 API 时间段当天到 x

问题描述 投票:0回答:1

我在 PowerBI 中调用了Azure 消耗 API 来获取有关资源成本等的最新信息。但是,存在长期最新信息的问题,而不是只有上个月至今的信息,我想要去年至今的日期。理想情况下,我希望获取从当前日期到云基础设施启动日期的数据,但现在一年就可以了。

我遇到的问题是类型问题,或者在 PowerBI 中称为数据格式错误。该错误显示“我们无法转换为日期”,但是我的代码has通过 Date.ToText() 函数将日期转换为文本。请求正文如下所示:

currentdate = Date.ToText(Date.From(DateTime.LocalNow)),
body = 
    "{
        ""type"": ""Usage"",
        ""timeframe"":""Custom"",
        ""timeperiod"": {
            ""from"" : ""2023-03-01T00:00:00+00:00""
            ""to"": """& currentdate & """,
        },
        ""dataset"": {
            ""aggregation"": {
                ""totalCost"": {
                    ""name"": ""Cost"",
                    ""function"": ""Sum""
                }
            },
            ""granularity"" : ""Daily"",
            ""grouping"": [
            {
                ""type"": ""Dimension"",
                ""name"": ""ResourceGroup""
            },
            {
                ""type"": ""Dimension"",
                ""name"": ""ServiceName""
            }
            ]
        }
    }"

我关注的代码是“时间范围”密钥对。 “from”设置为 2023 年 3 月 1 日,“to”应设置为当前日期。

有谁知道如何让脚本识别“当前日期”已转换为文本?

azure powerbi powerquery m
1个回答
0
投票

currentdate = Date.ToText(Date.From(DateTime.LocalNow)) 不会生成任何内容,因为它是错误代码

currentdate = Date.ToText(DateTime.Date(DateTime.LocalNow())) 将生成类似 3/28/2024 的文本

currentdate = Date.ToText(DateTime.Date(DateTime.LocalNow()), [Format="yyyy-MM-dd"]) 给出 2024-03-28

currentdate =  Date.ToText(DateTime.Date(DateTime.LocalNow()), [Format="yyyy-MM-dd"])&"T00:00:00+00:00" 

给出 2024-03-28T00:00:00+00:00 根据其他日期字段的格式,这可能是您想要的

© www.soinside.com 2019 - 2024. All rights reserved.