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.
Hello,
I thought I had figured this out once before however I'm stumped... I have data that looks something like this
Financial Acct | Detail Acct | Value |
Payable | Trade | 5 |
Payable | FX | 10 |
Receivable | Trade | 111 |
Pending | FI | 20 |
Pending | Equity | 25 |
Pending | Derivative | 50 |
I am using "Group By" based on {Financial Acct}. I am summing {Value}. What I'm struggling with is how to flatten the {Detail Acct} field into a single row based on the grouping. Desired output below. I tried using "All Rows" which provides a table but I'm not sure how to extract the values I want with a delimiter.
Financial Acct | Detail Account | Value |
Payable | Trade, FX | 15 |
Receivable | Trade | 111 |
Pending | FI, Equity, Derivative | 95 |
Thanks,
Brian
Solved! Go to Solution.
Hi @fox252 ,
yes, "All Rows" is the way to go. You can add a column with this formula then to retrieve the concatenated fields:Text.Combine([All][Detail Acct], ", ")
Please check out this solution:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkisTEzKSVXSUQopSkwB0aZKsTrI4m4RQMLQACwalJqcmlmGpsHQ0BCiJTUvJTMvHaTFE0gYGaCJuhaWZpZUgmRM0WRcUouAppZkloHtB+qLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Financial Acct" = _t, #"Detail Acct" = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Financial Acct", type text}, {"Detail Acct", type text}, {"Value", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Financial Acct"}, {{"SumValue", each List.Sum([Value]), type nullable number}, {"All", each _, type table [Financial Acct=nullable text, Detail Acct=nullable text, Value=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Detail Account", each Text.Combine([All][Detail Acct], ", ")),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"All"})
in
#"Removed Columns"
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi @fox252 ,
yes, "All Rows" is the way to go. You can add a column with this formula then to retrieve the concatenated fields:Text.Combine([All][Detail Acct], ", ")
Please check out this solution:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkisTEzKSVXSUQopSkwB0aZKsTrI4m4RQMLQACwalJqcmlmGpsHQ0BCiJTUvJTMvHaTFE0gYGaCJuhaWZpZUgmRM0WRcUouAppZkloHtB+qLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Financial Acct" = _t, #"Detail Acct" = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Financial Acct", type text}, {"Detail Acct", type text}, {"Value", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Financial Acct"}, {{"SumValue", each List.Sum([Value]), type nullable number}, {"All", each _, type table [Financial Acct=nullable text, Detail Acct=nullable text, Value=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Detail Account", each Text.Combine([All][Detail Acct], ", ")),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"All"})
in
#"Removed Columns"
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
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.
User | Count |
---|---|
102 | |
53 | |
21 | |
13 | |
11 |