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.
I have a string that I would would like to replace every third " " with "}, {". Below is an example of what I have currently and what I'm looking for.
current:
{24 1 0 188 1 0 190 1 0 192 1 0} |
{724 1 0 259 1 0 430 1 0 376 1 0 228 1 0 194 1 0} |
desired result:
{24 1 0}, {188 1 0}, {190 1 0}, {192 1 0} |
{724 1 0}, {259 1 0}, {430 1 0}, {376 1 0}, {228 1 0}, {194 1 0} |
Every string is made up of groups of three integers, but what's making this difficult is the fact that not every row has the same number of these groups. In another project I created a loop using the method described in this link, which I'm sure I could implement here but I have to believe that there is a simpler way of accomplishing this. Any help would be appreciated.
Solved! Go to Solution.
Hi @anjbauer1993,
I have a solution for you.
Split every text into a list by space, generate triples of the list, and combine these triples in a string again. The solution also contains your sample data.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqjYyUTBUMFAwtLCA0JYGUNoIRNcqxeoAFZlDVRmZWoJpE2OIKmNzM4i4EUy3CVRXLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]), Triples = Table.AddColumn( Source, "Triples", (_) => let // split text by space CurList = Text.Split([Column1], " "), // get count of values CurListLength = List.Count(CurList), // go through the list and group triples together Triples = List.Generate( () => 0, each _ < CurListLength, each _ + 3, each Text.Combine(List.Range(CurList, _, 3), " ") ), // combine triples CombineToText = Text.Combine(Triples, "}, {") in CombineToText ) in Triples
And a screenshot of the result.
Hi @anjbauer1993,
I have a solution for you.
Split every text into a list by space, generate triples of the list, and combine these triples in a string again. The solution also contains your sample data.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqjYyUTBUMFAwtLCA0JYGUNoIRNcqxeoAFZlDVRmZWoJpE2OIKmNzM4i4EUy3CVRXLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]), Triples = Table.AddColumn( Source, "Triples", (_) => let // split text by space CurList = Text.Split([Column1], " "), // get count of values CurListLength = List.Count(CurList), // go through the list and group triples together Triples = List.Generate( () => 0, each _ < CurListLength, each _ + 3, each Text.Combine(List.Range(CurList, _, 3), " ") ), // combine triples CombineToText = Text.Combine(Triples, "}, {") in CombineToText ) in Triples
And a screenshot of the result.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.