Forum Discussion

jsangerman's avatar
jsangerman
Helper II
2 years ago
Solved

Dynamic sorting for matrix column headers

I have a table of project milestones that looks something like this:

 

ProgramProjectMilestoneFinish
Program 1Project AMilestone 34/1/2020
Program 1Project AMilestone 25/1/2020
Program 1Project AMilestone 16/1/2020
Program 1Project BMilestone 27/1/2022
Program 1Project BMilestone 38/1/2022
Program 1Project BMilestone 19/1/2022

 

This would be repeated with Program 2 and a new set of Projects.

 

I'm creating a page where only 1 program is shown at a time, and a matrix that shows Projects in rows and Milestones in columns. For each program, I want the column headers to be sorted by the earliest (MIN) Finish date. So, for the program shown, I want them shown Milestone 3 | Milestone 2 | Milestone 1 from left to right.

 

Without other input, the Milestone column headers are sorted alphabetically. However, that doesn't work for the program shown, and each program could have a different order. I was thinking of creating a table to define the sort order for each program, but then learned that DAX tables can't take an input from the user (e.g., by filtered value).

 

Is there another way to define a sort for a subset of the data using a filtered defined by the user?

  • Hi jsangerman ,

     

    Columns cannot be custom sorted by using a measure - a physical column, calculated or created in PQ is necessary. Also, a unique item in a column cannot be sorted more than once  (eg Milestone 1 is either in the first or second order but not both).  As a workaround, you can create another column that references the original and append an invisible string to it. The count of which depends on the rank of the column value you were going to initially use for sorting. Please see attached sample pbix.

     

     

4 Replies