Forum Discussion

ns29's avatar
ns29
Helper I
6 years ago
Solved

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

    • ns29's avatar
      ns29
      Helper 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...

    • ns29's avatar
      ns29
      Helper 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!