Forum Discussion
m2oquestions
2 years agoRegular Visitor
How to pivot multiple rows to columns
Hi all, I'm working with an Excel data source that shows a series of payments that should be applied to a single invoice. (source file below) For each invoice [Bill ID] there is a single ...
- 2 years ago
Hi,
This M code works
let Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Payment Amount", type number}, {"Bill ID", type text}, {"Service Week Ending", type date}, {"Posted Week Ending", type date}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Bill ID", "Service Week Ending","Index"}, "Attribute", "Value"), #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Index", type text}}, "en-IN"),{"Attribute", "Index"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"), #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value") in #"Pivoted Column"Hope this helps.
DataNinja777
Super User
2 years agoHi m2oquestions ,
Does the output like below meet your requirement?
I used my favorite function ConcatenateX to summarize the information in one row per Bill ID.
I attach an example pbix file.