Forum Discussion
Sort Column in based on the Row total values in Matrix visual
- 2 months ago
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!
This scenario it is important to start with a key point: in Power BI, sorting column headers dynamically in a Matrix based on a measure (such as the Total of CTR) is not a native feature. The Matrix visual allows dynamic sorting for rows, but not for columns based on measure values.
- Create a relationship between the auxiliary table and your fact table using the column used in the Matrix columns.
- Select the Channel column in the auxiliary table.
- Apply Sort by column → SortOrder.
- Use this Channel field in the Matrix Columns section.
- Matrix does not support dynamic column sorting by measures.
- Auxiliary table with “Sort by column” is possible but static.
- A chart visual is the most practical solution when dynamic sorting is required.