Forum Discussion
Issue with pivoting via DAX
- 1 year ago
afaherty This can be easily done with Power Query no need to use DAX for data transformation.
let Source = RawData, Unpivot = Table.UnpivotOtherColumns ( Source, { "StudentID", "Level", "Test" }, "A", "V" ), MergeCols = Table.CombineColumns ( Unpivot, { "Test", "A" }, Combiner.CombineTextByDelimiter ( "_", QuoteStyle.None ), "Merged" ), Pivot = Table.Pivot ( MergeCols, List.Distinct ( MergeCols[Merged] ), "Merged", "V", ( x ) => x{0}? ) in Pivot
hello afaherty
you surely can do with DAX with some workaround (although this much easier with PQ).
you need to create measure for each category (math, math category, english, english category, and so on).
Math =
MAXX(
FILTER(
'Table',
'Table'[StudentID]=SELECTEDVALUE('Table'[StudentID])&&
'Table'[Level]=SELECTEDVALUE('Table'[Level])&&
'Table'[Test]="Math"
),
'Table'[Score]
)
Math Category =
MAXX(
FILTER(
'Table',
'Table'[StudentID]=SELECTEDVALUE('Table'[StudentID])&&
'Table'[Level]=SELECTEDVALUE('Table'[Level])&&
'Table'[Test]="Math"
),
'Table'[Category]
)
Thank you.
Thank you, thank you. The issue is that this is fake data and my real data has many more subjects other than math, english, science, and social studies.
- Irwan1 year ago
Super User
hello afaherty
if you are planning using DAX, then you need to re-define each subject either in measure or calculated table.
you can see divyed 's solution also define each subject.
if you dont want to define one by one, then you need to do this in PQ like ThxAlot and AntrikshSharma 's solution which is much easier in PQ for data transformation.
Hope this will help.
Thank you.