Forum Discussion
Grouping non-numerical rows
- 9 years ago
It is not clear from you question if this is something you are trying to do in the query editor or if you are trying to do this in DAX. Assuming you are trying to transform the data into your desired shape prior to modeling (i.e. using the query editor), here are steps that will lead you to the desired result.
First, in the query editor, select column "Things 1" and "Things 2". Then click "Unpivot Columns" in the Transform menu.
Second, filter out all rows with the value "null" in the resulting "Value" column.
Third, select the "Attributes" column and press "Pivot Column" in the Transform menu. In the resulting dialogue box, select "Value" for Values Column, press "Advanced Options" and select "Don't aggregate".
Here is the resulting M code:
let Source = Excel.Workbook(File.Contents("C:\testdata.xlsx"), null, true), Times_Sheet = Source{[Item="Times",Kind="Sheet"]}[Data], #"Changed Type" = Table.TransformColumnTypes(Times_Sheet,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Name"}, "Attribute", "Value"), #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] = "timestamp")), #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Attribute]), "Attribute", "Value") in #"Pivoted Column"
It is not clear from you question if this is something you are trying to do in the query editor or if you are trying to do this in DAX. Assuming you are trying to transform the data into your desired shape prior to modeling (i.e. using the query editor), here are steps that will lead you to the desired result.
First, in the query editor, select column "Things 1" and "Things 2". Then click "Unpivot Columns" in the Transform menu.
Second, filter out all rows with the value "null" in the resulting "Value" column.
Third, select the "Attributes" column and press "Pivot Column" in the Transform menu. In the resulting dialogue box, select "Value" for Values Column, press "Advanced Options" and select "Don't aggregate".
Here is the resulting M code:
let
Source = Excel.Workbook(File.Contents("C:\testdata.xlsx"), null, true),
Times_Sheet = Source{[Item="Times",Kind="Sheet"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Times_Sheet,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Name"}, "Attribute", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] = "timestamp")),
#"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Attribute]), "Attribute", "Value")
in
#"Pivoted Column"