使用 Power BI (PowerQuery) 获取 Azure 零售价格 Rest API
Get Azure Retail Prices using Power BI (PowerQuery) Rest API
在上图中我们有 Items 和 NextPageLink。数据存在于 Items 和 NextPageLink 中,包含下一页数据的 links。
我正在尝试使用具有多个页面的 Json 响应来自动执行 rest-API 调用。
这个想法是自动调用 NextPageLink 直到没有 NextPageLink。
我想将数据放入单个 table.
这是我用来提取数据的 link:https://prices.azure.com/api/retail/prices
这是最后一页 link:https://prices.azure.com/api/retail/prices?$skip=408500
请帮帮我
创建函数ReadSingle
(offset) =>
let Source =Json.Document(Web.Contents(" https://prices.azure.com/api/retail/prices?$skip="& Number.ToText( offset )))[Items]
in Source
使用循环读入数据。你可以重复直到完成,但坦率地说我的电脑锁住了,所以我正在做第 0-25 页,按 100's
let Source
= List.Generate(
() => [ Offset = 0, Data = ReadSingle(0) ],
each [Offset] <= 2500,
each [ Data = ReadSingle( [Offset] ),
Offset = [Offset] + 100 ],
each [Data]
),
z=Table.FromColumns(Source),
#"Added Index" = Table.AddIndexColumn(z, "Index", 0, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Index", "Attribute"}),
#"Expanded Value" = Table.ExpandRecordColumn(#"Removed Columns", "Value", {"currencyCode", "tierMinimumUnits", "retailPrice", "unitPrice", "armRegionName", "location", "effectiveStartDate", "meterId", "meterName", "productId", "skuId", "productName", "skuName", "serviceName", "serviceId", "serviceFamily", "unitOfMeasure", "type", "isPrimaryMeterRegion", "armSkuName"}, {"currencyCode", "tierMinimumUnits", "retailPrice", "unitPrice", "armRegionName", "location", "effectiveStartDate", "meterId", "meterName", "productId", "skuId", "productName", "skuName", "serviceName", "serviceId", "serviceFamily", "unitOfMeasure", "type", "isPrimaryMeterRegion", "armSkuName"})
in #"Expanded Value"
如果您愿意,可以交换以重复循环,直到 NextPageLink 为空。请参阅我最喜欢的参考资料 use List.Generate to make API Calls in Power Query M
在上图中我们有 Items 和 NextPageLink。数据存在于 Items 和 NextPageLink 中,包含下一页数据的 links。
我正在尝试使用具有多个页面的 Json 响应来自动执行 rest-API 调用。 这个想法是自动调用 NextPageLink 直到没有 NextPageLink。 我想将数据放入单个 table.
这是我用来提取数据的 link:https://prices.azure.com/api/retail/prices
这是最后一页 link:https://prices.azure.com/api/retail/prices?$skip=408500
请帮帮我
创建函数ReadSingle
(offset) =>
let Source =Json.Document(Web.Contents(" https://prices.azure.com/api/retail/prices?$skip="& Number.ToText( offset )))[Items]
in Source
使用循环读入数据。你可以重复直到完成,但坦率地说我的电脑锁住了,所以我正在做第 0-25 页,按 100's
let Source
= List.Generate(
() => [ Offset = 0, Data = ReadSingle(0) ],
each [Offset] <= 2500,
each [ Data = ReadSingle( [Offset] ),
Offset = [Offset] + 100 ],
each [Data]
),
z=Table.FromColumns(Source),
#"Added Index" = Table.AddIndexColumn(z, "Index", 0, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Index", "Attribute"}),
#"Expanded Value" = Table.ExpandRecordColumn(#"Removed Columns", "Value", {"currencyCode", "tierMinimumUnits", "retailPrice", "unitPrice", "armRegionName", "location", "effectiveStartDate", "meterId", "meterName", "productId", "skuId", "productName", "skuName", "serviceName", "serviceId", "serviceFamily", "unitOfMeasure", "type", "isPrimaryMeterRegion", "armSkuName"}, {"currencyCode", "tierMinimumUnits", "retailPrice", "unitPrice", "armRegionName", "location", "effectiveStartDate", "meterId", "meterName", "productId", "skuId", "productName", "skuName", "serviceName", "serviceId", "serviceFamily", "unitOfMeasure", "type", "isPrimaryMeterRegion", "armSkuName"})
in #"Expanded Value"
如果您愿意,可以交换以重复循环,直到 NextPageLink 为空。请参阅我最喜欢的参考资料 use List.Generate to make API Calls in Power Query M