Forum Discussion
Unpivot columns in table created from DAX epression
- 8 years ago
Hi BiBra,
Based on above table, to get the latest date for each "target name", please try below M code:
#"Grouped Rows" = Table.Group(#"Previous Step", {"target name"}, {{"AllRows", each _, Value.Type(#"Previous Step")}, {"Latest Date", each List.Max([date]), type number}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"date", "product1", "product2", "product3"}, {"AllRows.date", "AllRows.product1", "AllRows.product2", "AllRows.product3"})Then, you can unpivot this table to a new structure.
Regards,
Yuliana Gu
For me it is not necessary for it to be M code, DAX table or whatever. I just want the latest data to be retrieved from a query, and turned into a new table. Then I want to be able to unpivot some of the columns. Data is as follows:
name date product 1 product 2 product 3
hj 10/12-2016 1 0 1
as 9/10-2016 0 1 1
hj 10/9-2017 1 1 1
The latest data meaning, I want the latest data record for the specific name.
Hi BiBra,
Based on above table, to get the latest date for each "target name", please try below M code:
#"Grouped Rows" = Table.Group(#"Previous Step", {"target name"}, {{"AllRows", each _, Value.Type(#"Previous Step")}, {"Latest Date", each List.Max([date]), type number}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"date", "product1", "product2", "product3"}, {"AllRows.date", "AllRows.product1", "AllRows.product2", "AllRows.product3"})
Then, you can unpivot this table to a new structure.
Regards,
Yuliana Gu
- BiBra8 years ago
Helper III
I tried using this code.
However I still get information information about more than one date, for each target name
- v-yulgu-msft8 years ago
Microsoft Employee
- BiBra8 years ago
Helper III
I just want only the newest record for each target name. Not more than one. Then I want top be able to unpivot