Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Danny26
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
Eric_Zhang
Employee
Employee

@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
Eric_Zhang
Employee
Employee

@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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.