Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Sergiy
Resolver II
Resolver II

Is there a way using DAX to know the name of a column a Table visual is sorted by

Hi,

 

I wonder is there a way using DAX to know the name of a column a Table visual is sorted by.

 

My final aim is to write a DAX code that will be changing a visual title each time a user clicks on a column title.

When a user clicks on SalesAmount column title, the visual title should change to "The data is sorted by SalesAmount".

When a user clicks on OrderDate column title, the visual title should change to "The data is sorted by OrderDate".

And so on.

 

Any ideas are greatly appreciated.

 

SortedBy.png

 

 

 

7 REPLIES 7
jdbuchanan71
Super User
Super User

While @MattAllington is correct, there is no way for DAX to read the sort state of a visual there is an option that might work for you but it will require a couple steps.

  • Create a disconnected table with the list of measures you want to sort by, just as strings.
    Sort Measures = DATATABLE("Sort by",STRING,{{"Measure1"},{"Measure2"},{"SalesAmount"},{"Measure3"},{"Measure4"},{"Measure5"}})
  • Add a slicer to your visual using the disconnected table
  • Create a measure that reads the selected value from the slicer and returns that measure using SWITCH
    SortMeasure = 
    VAR SortingMeasure = SELECTEDVALUE ( 'Sort Measures'[Sort by], "SalesAmount")
    RETURN
    SWITCH(
        TRUE(),
        SortingMeasure = "Measure1",[Measure1],
        SortingMeasure = "Measure2",[Measure2],
        SortingMeasure = "Measure3",[Measure3],
        SortingMeasure = "Measure4",[Measure4],
        SortingMeasure = "Measure5",[Measure5],
        SortingMeasure = "SalesAmount",[SalesAmount],
        [Sales Amt]
    )
  • Add that sort measure to the end of your table and sort by that.  When the selected measure changes, the vale fed into [SortMeasure] will change and the sorting will change.
    • You can make the column of [SortMeasure] in your table so narrow it doesn't show.
  • Add a measure that generates your title.
    Sort Title = 
    VAR SortingMeasure = SELECTEDVALUE ( 'Sort Measures'[Sort by], "SalesAmount")
    RETURN "This table is being sorted by " & SortingMeasure

sortbytitle.jpg

@jdbuchanan71 , thank you for trying to find a way.

 

The solution you created implies that a user is expected to change the sorting column by clicking on a slicer and never on column titles.

I am afraid we can't direct a user to click on a slicer if he is accustomed to clicking on a column title. And if he does click on a column title then your solution won't work.

But anyway, thank you for paying attention to my question and trying to help!

@Sergiy I was betting the solution wouldn't work, it is quite a change, but thought I would offer it up anyway.

Cheers!

In the latest version of PBI Desktop, it is possible to turn on a visual level "help" icon with a custom message (Tool tip).  You could turn this on.  When the user hovers over the ?, you can present them instructions on what to do. There is already an arrow icon indicating which column is sorted and in which direction.  



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

@MattAllington ,

>There is already an arrow icon indicating which column is sorted and in which direction.  

I'd add there is another way for a user to get to know which column is currently sorted and choose another one for a new sorting order:

Menu.png

 

What I wanted is just to add a bit more comfort to a user filling a visual title not only with a context information(columns that are sliced by, scope, etc.) but with a current sorting order.

Explanations, in a form of a Tool tip or something of the kind, of why a user shouldn't click on a column title nor use a menu provided by ellipses wouldn't add the comfort I thought of.

 

Nevertheless, thank you both for sharing your ideas.

If I ever come to a solution (I am aware the chances are low) I'll let you know here.

MattAllington
Community Champion
Community Champion

No, there is no access to the sort staus of a visual that is accessible by DAX. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

It would be useful if there was a way.

 

By the way, @MattAllington , thank you for "Six Sigma Control Charts" solution. I like it.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors