Forum Discussion
How to pivot a table (created using DAX-SUMMARIZED, not Power Query) on a column?
- 4 years ago
Hi, Anonymous
According to your description, you want to pivot a table (created using DAX-SUMMARIZED, not Power Query) on a column. Right?
Here are the steps you can follow:
(1)This is my test data: ‘Test’
(2) We can click “New Table” and enter DAX :
Table = ADDCOLUMNS( SUMMARIZE('Test','Test'[GATEGORY]) ,
"2019" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2019},Test[YEAR])),
"2020" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2020},Test[YEAR])),
"2021" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2021},Test[YEAR])),
"2022" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2022},Test[YEAR]))
)
(3)Then we can meet your need , the result is as follows :
And according to what you said later, if you want to display the corresponding effect in the Matrix visual object, you can hide the previous [GATEGORY] in the following ways:
(1)We can close wrap function in "Format" pane:
(2) We can hover over our header and drag to hide the fields for our column:
If this method cannot help you solve the problem, you can delete your private data and provide your sample data in the form of a table or .pbix file, and describe your detailed needs, so that we can better help you solve the problem.
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
For anyone reading this thread and having the same problem as Anonymous (and me!) with the TREATAS function, you need to put the names in the {} brackets in between ""
The mention of a strategy that works above is different:
Table = ADDCOLUMNS( SUMMARIZE('Test','Test'[GATEGORY]) ,
"2019" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2019},Test[YEAR])),
"2020" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2020},Test[YEAR])),
"2021" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2021},Test[YEAR])),
"2022" , CALCULATE( SUM('Test'[TOTAL]) , TREATAS( {2022},Test[YEAR]))
)
So the rule is likely: wrap in quotes when the value is string/text and do not wrap in quotes when the value is a number.