Forum Discussion

Shinu1's avatar
Shinu1
Icon for Helper II rankHelper II
6 years ago

Change sort order based on measure selection

Hi,

I am not sure how to change the sort order based  a measure selection. 

I have a matrix table showing measure based on the selection from a slicer. My problem is with the sorting order based on selection.

 

Example :

 

Slicer                       Matrix Table

ER                            Accounts    Total

CM                           a                 100

TC                            b                   40

TR                            c                   90

 

When I select "ER" or  "TR" from slicer, i want the table to sort the measure in Descending order and on "CM" and "TC" selection, the sorting order should change to Ascending order

 

Please advise how can i achieve it.

 

Thanks

Shinu

 

 

 

9 Replies

  • Shinu1 I'm afraid that you can change the sort order based on the selection. What is the use case that you need to change the sort order, maybe there is another solution.

    • Shinu1's avatar
      Shinu1
      Icon for Helper II rankHelper II

      Different measures are looked with different perspective.

      Example: The Cost line items are all in negative and hence the highest negative amount needs to pulled at the top in matrix table and viceversa for Reveue/Profit.

      Hope I'm clear

       

      Thanks

      Shinu

      • parry2k's avatar
        parry2k
        Icon for Super User rankSuper User

        Shinu1 I didn't see any negative value in your sample dataset and that's why it was not clear. 

  • mhossain's avatar
    mhossain
    Icon for Solution Sage rankSolution Sage

     

     

    Hi Shinu1 

     

    Try below, I don't know your table names, "tbl_Processed_Rawdata" you can try "ALL" in below dax, basically we want to clear the slicer selection while calculating the rank, ranks should be based on all the KPIs, so adjust below measures or provide me the snapshot of sample data, hope this makes sense.

     

     

    Rank Measure =

     

    VAR selected =
    SELECTEDVALUE ( tbl_KPI[KPI] )
    VAR rankER = RANKX(All(tbl_Processed_Rawdata),[ExternalRevenue],,DESC)
    VAR rankCM = RANKX(All(tbl_Processed_Rawdata),[Contribution Margin],,ASC)
    VAR rankTC = RANKX(All(tbl_Processed_Rawdata),[Total Cost],,ASC)
    VAR rankTR = RANKX(All(tbl_Processed_Rawdata),[Total Revenue],,DESC)
    RETURN
    SWITCH ( selected, "ER", rankER, "CM", rankCM, "TC", rankTC, "TR", rankTR )