cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

How to split Azure resource tags in to separate colums

Hi All,

 

After much research and trial and error I am trying to figure out a way to parse the Azure resource tags that are exported using the Azure Enterprise connector and use them against other metrics for cost analysis etc. I know you can split the column "Tags" based on a delimiter and assuming the correct tags are applied in the same order for each resource in to separate column's but in our environment the number of tags applied could vary. Below is an example of how the tags are displayed in the exported table. 

 

{"Hostname":"TestSvr01","Location":"Sydney","Project":"12345","Workload":"TestApp1","Workorder":"1234"}


 What I am trying to achieve is a script or a query which would search for a key word in the Tags column and then place that value into a separate column e.g. Search for the keyword Hostname and place the value next to it in a new column called hostnames. Because a resource/VM could have multiple "Workload" tags I need a method to parse the string instead of using straight delimiters to column process. 

Any help with this would be very much appreciated and please ask me to clarify if anything is unclear.

On a side note I am very surprised that MS make reporting on resource tags so difficult. 

 

Thanks

Danny

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: How to split Azure resource tags in to separate colums

@Danny26

That looks like a  valid JSON string. Try to add a custom column with Json.Document and expand the column accordingly.

let
    Source = Table.FromRows({{1,"{""Hostname"":""TestSvr01"",""Location"":""Sydney"",""Project"":""12345"",""Workload"":""TestApp1"",""Workorder"":""1234""}
"},{2,"{""Hostname"":""TestSvr02"",""Location"":""NewYork"",""Project"":""12345"",""Workload"":""TestApp1"",""Workorder"":""1234""}
"}},{"id","tags"}),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Json.Document([tags])),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Hostname", "Location", "Project", "Workload", "Workorder"}, {"Custom.Hostname", "Custom.Location", "Custom.Project", "Custom.Workload", "Custom.Workorder"})
in
    #"Expanded Custom"

 

Capture2.PNGCapture.PNG

View solution in original post

1 REPLY 1
Highlighted
Microsoft
Microsoft

Re: How to split Azure resource tags in to separate colums

@Danny26

That looks like a  valid JSON string. Try to add a custom column with Json.Document and expand the column accordingly.

let
    Source = Table.FromRows({{1,"{""Hostname"":""TestSvr01"",""Location"":""Sydney"",""Project"":""12345"",""Workload"":""TestApp1"",""Workorder"":""1234""}
"},{2,"{""Hostname"":""TestSvr02"",""Location"":""NewYork"",""Project"":""12345"",""Workload"":""TestApp1"",""Workorder"":""1234""}
"}},{"id","tags"}),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Json.Document([tags])),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Hostname", "Location", "Project", "Workload", "Workorder"}, {"Custom.Hostname", "Custom.Location", "Custom.Project", "Custom.Workload", "Custom.Workorder"})
in
    #"Expanded Custom"

 

Capture2.PNGCapture.PNG

View solution in original post

Helpful resources

Announcements

August Community Highlights

Check out a full recap of the month!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors