Our plan today
- Find REST API we want to use
- Connect to REST API in Power BI
- Create tables and structure the data
1. Find REST API we want to use
For this we are going to use the Azure Lab Services REST API.
Link to the documentation is here https://docs.microsoft.com/en-us/rest/api/labservices/
2. Connect to REST API in Power BI
- Create a new Power BI Report
- Click on Transform data
- Click New Source
- Select Blank Query
- Click Advanced Editor and paste in the following:
let GetManagementBaseUri=(govKind as text) as text =>
let
managementUrl = if govKind ="us-government" then "https://management.usgovcloudapi.net"
else if govKind="germany-government" then""
else if govKind = "china" then "https://management.chinacloudapi.cn"
else "https://management.azure.com"
in
managementUrl
in GetManagementBaseUri
- Rename the Blank Query to GetManagementURL
- Create a new blank query
- Paste in the following:
let
GetPages = (Path)=>
let
Source = Json.Document(Web.Contents(Path)),
LL= @Source[value],
result = try @LL & @GetPages(Source[#"nextLink"]) otherwise @LL
in
result,
Fullset = GetPages(GetManagementURL(AzureKind)&"/subscriptions?api-version=2020-01-01"),
#"Converted to Table" = Table.FromList(Fullset, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "authorizationSource", "managedByTenants", "subscriptionId", "tenantId", "displayName", "state", "subscriptionPolicies", "tags"}, {"id", "authorizationSource", "managedByTenants", "subscriptionId", "tenantId", "displayName", "state", "subscriptionPolicies", "tags"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Column1",{"managedByTenants"}),
#"Expanded subscriptionPolicies" = Table.ExpandRecordColumn(#"Removed Columns", "subscriptionPolicies", {"locationPlacementId", "quotaId", "spendingLimit"}, {"locationPlacementId", "quotaId", "spendingLimit"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded subscriptionPolicies",{"tags"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"displayName", "Subscription Name"}}),
#"Removed Columns2" = Table.RemoveColumns(#"Renamed Columns",{"id"})
in
#"Removed Columns2"
- Rename to All Subscriptions
- Create a new blank query
- paste in the following:
"global" meta [IsParameterQuery=true, List={"us-government", "global", "china"}, DefaultValue="global", Type="Text", IsParameterQueryRequired=true]
- Rename to AzureKind
e1feef23-e9e3-43a7-9d4c-4298173cd19e rg-prd-lab-dsk-55-502819 prd-lab-dsk-55-502819 55-502819-Network Services and Administration