Forum Discussion
Sort date field in Matrix column header descending
I have already seen the following:
https://www.excelguru.ca/blog/2018/06/14/ranking-method-choices-in-power-query/
https://stackoverflow.com/questions/49685042/powerbi-sort-columns-in-matrix-visual
I am having a hard time understanding the solution. Honestly, I'm just looking for a pivot table kind of solution. Please attached screenshot.
Thanks!
Hi ns29 ,
We can use the following steps to meet your requirement:
1. create a calculated table using following DAX:
ColumnHeader = ADDCOLUMNS ( CROSSJOIN ( DATATABLE ( "ValueHeader", STRING,"ValueRank",INTEGER, { { "%_of_sample",2 }, { "metric_value_1" ,1}, { "metric_value_2",3 } } ), DISTINCT ( 'Table1'[metric_month] ) ), "Rank", RANKX ( DISTINCT ( 'Table1'[metric_month] ), [metric_month], , DESC, DENSE ) )2. Make metric_month column sort by Rank column, then make ValueHeader sort by Rank column.
3. create relationship between two tables based on the ColumnHeader column
4. create a measure used in the value field of matrix visual:
ValueInMatrix = SWITCH(SELECTEDVALUE('ColumnHeader'[ValueHeader]),"metric_value_1",SUM('Table1'[metric_value_1])&"","metric_value_2",SUM('Table1'[metric_value_2])&"","%_of_sample",FORMAT([%_of_sample],"Percent"))
Best regards,
8 Replies
- amitchandakSuper User
Can you share sample data and sample output. If possible please share a sample pbix file after removing sensitive information.Thanks.
Proud to be a Datanaut My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970- ns29Helper I
amitchandak Thank you for the quick response! Happy to send over samples but have a super rookie question - how do I attach anything other than images on here? So embarrased to ask...
- amitchandakSuper User
You can upload to dropbox, onedrive and share
- v-lid-msftCommunity Support
Hi ns29 ,
We can create two calculated column, then use ShowDate Column to sort by rank column and use ShowDate Column as column header to meet your requirement:
Calculated Columns:
ShowDate = [Date]Rank = RANKX('Table',[Date],,,Dense)Sort by:
Matrix visual:
Best regards,- ns29Helper I
v-lid-msft thanks for your response. Seems like the proposed solution is similar to other solutions I've seen. Baffles me that something so apparently simple requires such a complicated workaround. But there are probably good reasons why the product is designed this way which my simple mind may not be able to comprehend. I'll give it a shot and report back.
PS: I get the Rank field but what is the point of the ShowDate field since it appears to be identical to the Date field. I'm trying to understand the mechanics rather than blindly apply the solution. Thanks again!