Forum Discussion

craigmday's avatar
craigmday
Helper I
3 months ago
Solved

Unable to sort matrix visual values by month

Hi there,   I have a matrix visual where I am displaying sales values by month (columns) for a list of customers (rows). I have a relationship between my sales table and my calendar table, so I am ...
  • Shai_Karmani's avatar
    3 months ago

    The matrix does not pass the clicked column's filter context into the sort measure. When you sort a matrix by a measure, the engine evaluates that measure once per row using the full row context (effectively the row total, with all columns visible), so SELECTEDVALUE on Calendar[Month] returns blank and the measure falls back to the year total. That is the same behavior whether you click a column header or use "Sort by" in the visual menu.

    The standard workaround is to drive the sort from a slicer or a field parameter rather than the column you click. Add a single select slicer with the month name, and have your sort measure read from that slicer:

    Sort by Month =
    VAR _m = SELECTEDVALUE ( 'Sort Selector'[Month] )
    RETURN CALCULATE ( [Sales], 'Calendar'[Month] = _m )

    Then sort the matrix by [Sort by Month] descending. When the user picks a month in the slicer, the rows reorder by that month's sales.

    If this helped, a thumbs up and accepting the solution would be appreciated.

    Best,
    Shai Karmani

    Let's connect in LinkedIn