Forum Discussion
How to remove GUID from rows in a column when it is combined with other text?
So I have a query that imports rows such as
| \\Server\Database\Unit01\Reactor?2f2eb94f-adb5-11eb-bacf-f0d5bf3c2f98|TEMP?b67078ec-0420-569f-204e-f6c9c28a9896 |
Where that string of characters is the GUID of the asset. Is there a way to dynamically remove the GUID from the row so it will look like
\\Server\Database\Unit01\Reactor|TEMP
but also be applicable to other GUIDs?
aman720 Try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc1BDoIwEEDRu7B2TFuhtCs2kLjQaLQkJgyLmTKTuNEEiSsOrx7Af4D3h6HAb1eZ3zIjtrQQ00sQ+8d9MRbxIpSX59w4dcKxVKCJK7BWGJiygpqpYt1lpzGsqTueG/a1qYNkMKUzUPmo4EwpoD7H7ALFEH0xbv6N97f11KdDl7Y/rRjHDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}), #"Added Custom2" = Table.AddColumn(#"Changed Type", "Custom2", each Text.BeforeDelimiter([Column1], "?", {0, RelativePosition.FromEnd})), #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom3", each if Text.Length([Custom2]) = 0 then [Column1] else [Custom2]), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom3",{"Column1", "Custom2"}), #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns1",{{"Custom3", "Column1"}}), #"Added Custom" = Table.AddColumn(#"Renamed Columns1", "Custom", each "?" & Text.BetweenDelimiters([Column1], "?", "|", {0, RelativePosition.FromEnd}, 0)), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Replacer.ReplaceText([Column1],[Custom],"")), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Column1", "Custom"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "Column1"}}) in #"Renamed Columns"
7 Replies
- Greg_DecklerCommunity Champion
aman720 Try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("DcE7DsIwDADQu3S35JgkTaYuMCIhPlPdwU5tiaVIJWLi8PDePA/8d7P9YzvzUbqovI35sT07BuarSeuvfSIn0xodZNUEIZiCSnNwXJP6oZHX8r2fzpdJ84hjsQYYCSHl6kAYDTy32qhILTUPy/ID", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}), #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Changed Type", {{"Column1", each Text.BeforeDelimiter(_, "?", {0, RelativePosition.FromEnd}), type text}}), #"Added Custom" = Table.AddColumn(#"Extracted Text Before Delimiter", "Custom", each "?" & Text.BetweenDelimiters([Column1], "?", "|", {0, RelativePosition.FromEnd}, 0)), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Replacer.ReplaceText([Column1],[Custom],"")), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Column1", "Custom"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "Column1"}}) in #"Renamed Columns"- aman720Regular Visitor
Greg_Deckler I apologize I am still quite new to Power BI. I have the data pulled in from SQL. I will call the column Column1 to fit your syntax. How does that fit into the overall steps? For example, do I drop that in after Source in the Applied Steps. Thanks!
Edit: Actually I got it to work with your code. So thanks for that! In doing so, I found not all the rows have that GUID in them and what you wrote puts in a blank row if there is no GUID (my bad). I am trying to find a way to skip these rows if they don't have the GUID now.
- Greg_DecklerCommunity Champion
aman720 Can you provide an example of one without GUIDs?