Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello all,
I am struct with a problem in power query. Below is what data in single column.
Colum1
Name1
Value11
Value12
Value13
Name2
Value21
Value22
Value23
Result that I want is
Column 1, Column 2
Name1, "Value11,Value12,Value13"
Name2, "Value21,Value22,Value23"
Thanks to all for contribution to this community.
Solved! Go to Solution.
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WUorViVbyS8xNNQSzwERYYk5pqiGGgBG6gDFCAGQCurwRuglGGCqAJsQCAA==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type text) meta [Serialized.Text = true])
in
type table[Colum1 = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Colum1", type text}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Colum1] <> null and [Colum1] <> ""),
#"Grouped Rows" = Table.Group(
#"Filtered Rows",
{"Colum1"},
{{"all", each Table.Transpose(_)}},
GroupKind.Local,
(x, y) => Number.From(Text.Start(x[Colum1], 4) = Text.Start(y[Colum1], 4))
),
#"Expanded all" = Table.ExpandTableColumn(
#"Grouped Rows",
"all",
{"Column2", "Column3", "Column4"},
{"all.Column2", "all.Column3", "all.Column4"}
)
in
#"Expanded all"
this code works for any column that has groups of any size delimited by words that have the first 4 equal characters
let
Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("i65Wcs7PKc3NM1SyUvJLzE01VKrVQRIzNELlGqNyTVG4YAOMUA1QSja0RBNJMTJAE0k1AlobCwA=",BinaryEncoding.Base64),Compression.Deflate))),
acc = List.Accumulate(
Source[Column1]&{"Name"},{{}, {}},
(s,c)=>if s{0}={} then {{c},{}}
else if c is text and Text.StartsWith(c, "Name") then {{c}, s{1}&{{s{0}{0}}&{Text.Combine(List.Transform(List.Skip(s{0}),Text.From),", ")}}}
else {s{0}&{c}, s{1}}
){1},
result = Table.FromRows(acc)
in
resultIf you have data below 2000 lines, you can also use the List.Accumulate function solution. Although I also like List.Accumulate, it handles more than 2000 lines of data and is prone to stack overflows
let
Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("i65Wcs7PKc3NM1SyUvJLzE01VKrVQRIzNELlGqNyTVG4YAOMUA1QSja0RBNJMTJAE0k1AlobCwA=",BinaryEncoding.Base64),Compression.Deflate))),
acc = List.Accumulate(
Source[Column1]&{"Name"},{{}, {}},
(s,c)=>if s{0}={} then {{c},{}}
else if c is text and Text.StartsWith(c, "Name") then {{c}, s{1}&{{s{0}{0}}&{Text.Combine(List.Transform(List.Skip(s{0}),Text.From),", ")}}}
else {s{0}&{c}, s{1}}
){1},
result = Table.FromRows(acc)
in
resultIf you have data below 2000 lines, you can also use the List.Accumulate function solution. Although I also like List.Accumulate, it handles more than 2000 lines of data and is prone to stack overflows
Hi, @Greatbi1
let
Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("i65Wcs7PKc3NM1SyUvJLzE01VKrVQRIzNELlGqNyTVG4YAOMUA1QSja0RBNJMTJAE0k1AlobCwA=",BinaryEncoding.Base64),Compression.Deflate))),
result = Table.Group(Source,"Column1",{"Column2",each Text.Combine(List.Transform(List.Skip([Column1]),(x)=>Text.From(x)),", ")},0,(x,y)=> Byte.From(y is text and Text.StartsWith(y,"Name")) )
in
result
If my solution solves your problem, please mark it as a solution
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WUorViVbyS8xNNQSzwERYYk5pqiGGgBG6gDFCAGQCurwRuglGGCqAJsQCAA==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type text) meta [Serialized.Text = true])
in
type table[Colum1 = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Colum1", type text}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Colum1] <> null and [Colum1] <> ""),
#"Grouped Rows" = Table.Group(
#"Filtered Rows",
{"Colum1"},
{{"all", each Table.Transpose(_)}},
GroupKind.Local,
(x, y) => Number.From(Text.Start(x[Colum1], 4) = Text.Start(y[Colum1], 4))
),
#"Expanded all" = Table.ExpandTableColumn(
#"Grouped Rows",
"all",
{"Column2", "Column3", "Column4"},
{"all.Column2", "all.Column3", "all.Column4"}
)
in
#"Expanded all"
this code works for any column that has groups of any size delimited by words that have the first 4 equal characters
Hi @Anonymous , Just need one more help. Can you please explain how group rows is working.
I could not explain it better than as done by @imke here, where you can also find other examples of use of the fifth element.
do not hesitate to ask if you still need specific clarifications for "your" specific case ...
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |