Forum Discussion
Azure Cost Management - Splitting Out Tags
- 6 years ago
Sorry about that, I was using it on some older code.
Find the correct code here:
application =
VAR tag = "application"
VAR textLength =
FIND( ",",
Sheet3[Tags],
FIND(tag,Sheet3[Tags])+LEN(tag)+3)-(FIND(tag,Sheet3[Tags])+LEN(tag)+3)-1
RETURN
MID(
Sheet3[Tags],
FIND(tag,Sheet3[Tags])+LEN(tag)+3,
textLength)I have also added the Variable tag. Now, you simply have to get whatever tag you're looking for and replace "application" with the tag.
This should solve your issue! Please mark this post as the solution to help others! 😁
- Anonymous6 years ago
Hey all,
Not sure if anyone's still having trouble with this, but thought I'd share the method I used to work with tags.
The Tags field in Azure Cost Management is almost JSON format, but is missing the opening and closing curly braces.
By adding these back, I was then able to use Transform -> JSON without error.
Example:
#"Added Custom" = Table.AddColumn(usagedetails, "Tags JSON", each Text.Combine({"{ ", [Tags], " }"})), #"Parsed JSON" = Table.TransformColumns(#"Added Custom",{{"Tags JSON", Json.Document}}),Hope that helps someone!
I'm curious as to why the splitting of columns doesn't provide the solution you are looking for.
Here is what I did:
- Split Column by Delimiter - ","
- Renamed the columns: Application, Environment, Budget, Client
- Extracted Text After Delimiter - ":"
This was my final result:
M Query:
let
Source = [Source],
#"Changed Type" = Table.TransformColumnTypes([Source],{{"Column1", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Tags", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type1", "Tags", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Tags.1", "Tags.2", "Tags.3", "Tags.4"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Tags.1", type text}, {"Tags.2", type text}, {"Tags.3", type text}, {"Tags.4", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type2",{{"Tags.1", "Application"}, {"Tags.2", "DataBricks Environment"}, {"Tags.3", "Budget"}, {"Tags.4", "Client"}}),
#"Extracted Text After Delimiter" = Table.TransformColumns(#"Renamed Columns", {{"Application", each Text.AfterDelimiter(_, ":"), type text}, {"DataBricks Environment", each Text.AfterDelimiter(_, ":"), type text}, {"Budget", each Text.AfterDelimiter(_, ":"), type text}, {"Client", each Text.AfterDelimiter(_, ":"), type text}})
in
#"Extracted Text After Delimiter"
- RyanBrantley6 years agoFrequent Visitor
Ah, ok. Thanks - just realized that the screen cap makes it look like the tags are always structured in the same order.
The tags come in random order. So I might see
- "client":"123","tag2:"foo"
- "tag2:foo","client":"abc"
And we usually have 5-10 tags, all randomly ordered, against 350k+ rows.
- bfernandez6 years agoResolver II
It's hard for me to undertsnad how the data does not come directly from Azure in the JSON format you are expecting. Be sure you are using the correct versions and are applying the correct Power Query steps.
If this does not solve your issue, you can apply the following workaround in DAX:
Hostname = VAR textLength = FIND ( ",", Table1[Tags], FIND ( "Hostname", Table1[Tags] ) + LEN ( "Hostname" ) + 3 ) - ( FIND ( "Hostname", Table1[Tags] ) + LEN ( "Hostname" ) + 3 ) - 1 RETURN MID ( Table1[Tags], FIND ( "Hostname", Table1[Tags] ) + LEN ( "Hostname" ) + 3, textLength )It's not the neatest solution but it will get the job done. Of course, you would need to replace "Hostname" with whichever tags you are looking for.
Hopefully this helps!
- RyanBrantley6 years agoFrequent Visitor
Yea, not sure what is going on with them not being JSON, but I double checked that I'm using the Azure Cost Management connecter.
I think your idea would definitely work, because I'm only trying to extract 2 or 3 tags.
I modified it for my tables, colums, and tags, but DAX is giving me an error return with the message "The search Text provided to function 'Find' could not be found in the given text.'
- Anonymous5 years agoNot applicable
This would be a great option you have shown but it doesnt work when tags may be in different orders or some rows don't have the same tags or if Tag names have different spellings.
Is there a way to use this when you have a wide range of tags and up to 14 different tag names but with them in different orders and not all the same?