Forum Discussion

SUMESHKUMAR22's avatar
SUMESHKUMAR22
Helper IV
2 months ago
Solved

Sort Column in based on the Row total values in Matrix visual

Hi Team, Please help me with the below usecase. In the attached Power BI Matrix image, the column headers are not fixed categories there can be more new ones in future ( so I want the column he...
  • Gautam_Kumar01's avatar
    2 months ago

    Hi SUMESHKUMAR22 

     

    You can sort Matrix columns dynamically based on Row Total using a Rank measure + Sort by Column.

     

    Since your column headers are dynamic, we need to rank them by the Total CTR value.

     

    **SOLUTION:**

     

    **Step 1: Create this Measure**

    This calculates total CTR for each column

     

    Total CTR =

    VAR _CurrentCol = SELECTEDVALUE('Your table name')

    RETURN

    CALCULATE([CTR], ALL('YourTable'))[YourColumnHeader][YourRowFie

    ld]

     

    **Step 2: Create Rank Measure for Sorting**

     

    Column  Sort Rank =
    RANKX(
    ALLSELECTED('YourTable'),
    [Total CTR],
    ,
    DESC,
    DENSE
    )[YourColumnHeader]

     

     

    **Step 3: Apply the Sort**

    1. Click on your `YourColumnHeader` field in the Fields pane

    2. Go to `Column tools` tab > `Sort by column` > Select `Column Sort Rank`

     

    **Result:**

    Now columns will automatically sort from Highest Total to Lowest Total: CB | TQ | QW | AS | ER | YW

    When new columns are added in future, they will also sort automatically based on Total row value.

     

    **Important Notes:**

    1. Replace `YourTable` with your table name

    2. Replace `YourColumnHeader` with OD, YW, CB etc field

    3. Replace `YourRowField` with LHR-PAR, PAR-LHR field

    4. Turn OFF "Show items with no data" for Column field

     

    This works because `RANKX` recalculates on every filter change, so when date filter changes, column order will also change.

     

    Let me know if you need help with the exact field names. Happy to help!