Forum Discussion
Pivot data in powerquery
- 7 years ago
Unpivot would do the job if the Event names were in the column headers. With this data structure there will be no quick and easy solution I'm afraid
If the data is coming from an Excel pivot, why not just rearrange it in Excel?
Did I answer your question? Mark my post as a solution!
Proud to be a Datanaut!
Unpivot would do the job if the Event names were in the column headers. With this data structure there will be no quick and easy solution I'm afraid
If the data is coming from an Excel pivot, why not just rearrange it in Excel?
Proud to be a Datanaut!
I accept your post as a solution since i agree there isnt an easy way to make this work...however, one thing that just might work (but is not a good time investment) is to chop the table into several ones via DAX and then append the tables together...you're right, ill just do it through excel :)
Thanks,
Dat_Data
- Zubair_Muhammad7 years agoCommunity Champion
Anonymous Stachu
Pardon my intrusion. There is a little trick which might work (I think I learnt from one of parry2k 's solutions which used Number.Mod)
I am attaching the Excel file. See if this useful.
It works with the sample data and mostly done using Query Editor's interfacelet Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text},
{"Column3", type any}, {"Column4", type text}, {"Column5", type any}, {"Column6", type text}, {"Column7", type any}, {"Column8", type text}, {"Column9", type any}, {"Column10", type text}, {"Column11", type any}, {"Column12", type text}, {"Column13", type any}, {"Column14", type text}, {"Column15", type any}, {"Column16", type text}, {"Column17", type any}, {"Column18", type text}, {"Column19", type any}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value"), #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Column1] <> "Category")), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute"}), #"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 0, 1), #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each [Index]-Number.Mod([Index],Table.RowCount(Source)-1)), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Index"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Custom", "Column1", "Value"}), #"Grouped Rows" = Table.Group(#"Reordered Columns", {"Custom", "Column1"}, {{"All", each _[Value]}}), #"Removed Columns2" = Table.RemoveColumns(#"Grouped Rows",{"Custom"}), #"Added Custom1" = Table.AddColumn(#"Removed Columns2", "Custom", each Text.Combine(List.Transform([All],each Text.From(_)),"|")), #"Removed Columns3" = Table.RemoveColumns(#"Added Custom1",{"All"}), #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns3", "Custom", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Custom.1", "Custom.2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Custom.1", type text}, {"Custom.2", type datetime}}) in #"Changed Type1" - Stachu7 years agoCommunity Champion
oh absolutely, you can also do it with PowerQuery/M, not only DAX, but I honestly don't think it's worth the time