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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
ldwf
Helper V
Helper V

How to sort a tooltip table viz in ascending or descending order automatically based on field value

I have a simple table visual that I am using in a tooltip that needs to be sorted, but the requirement is not to sort it by default in either ascending or descending order by a certain value, but rather to sort it in either ascending or descending order dynamically depending on a field value for the row the user hovers over.  The field is called 'Direction', and if the Direction value for that row is 'Up', I want the rows in the tooltip to be sorted by the measure  in ascending order; and if the Direction is 'Down', I want the rows sorted by the measure in descending order.  The Direction value will always be either 'Up' or 'Down' for every record in the tooltip visual, whenever the user hovers over the row in the table.  Currently I am sorting it in descending order by the measure, but depending on the record the user hovers over, they may need it sorted in ascending order.

1 ACCEPTED SOLUTION
ldwf
Helper V
Helper V

I was able to get this to work by just creating a dynamic rank measure, then adding it to the tooltip visual, then sorting the visual in ascending order by this rank measure.  This is the DAX code for the measure:

Dynamic Rank =
var SortDirection=[Goal Direction]
RETURN
 SWITCH(
    TRUE(),
    SortDirection="Up",
        RANKX(ALLSELECTED('Fact Table'),[Current and Prior Month Variance], ,ASC,Dense),
    SortDirection="Down",
        RANKX(ALLSELECTED('Fact Table'),[Current and Prior Month Variance], ,DESC,Dense)
 )

View solution in original post

4 REPLIES 4
ldwf
Helper V
Helper V

I was able to get this to work by just creating a dynamic rank measure, then adding it to the tooltip visual, then sorting the visual in ascending order by this rank measure.  This is the DAX code for the measure:

Dynamic Rank =
var SortDirection=[Goal Direction]
RETURN
 SWITCH(
    TRUE(),
    SortDirection="Up",
        RANKX(ALLSELECTED('Fact Table'),[Current and Prior Month Variance], ,ASC,Dense),
    SortDirection="Down",
        RANKX(ALLSELECTED('Fact Table'),[Current and Prior Month Variance], ,DESC,Dense)
 )
v-abhinavmu
Community Support
Community Support

Hi @ldwf,

Thank you for posting your query in the Microsoft Fabric Community Forum, and thanks to @danextian & @Shravan133  for sharing valuable insights.

 

Could you please confirm if your query has been resolved by the provided solutions? This would be helpful for other members who may encounter similar issues.

 

Thank you for being part of the Microsoft Fabric Community.

danextian
Super User
Super User

Hi @ldwf

Power BI does not have awareness of which measure is being hovered in a table or matrix visual. A common workaround is to use a matrix visual and format it to look like a table, combined with a disconnected table that holds the measure names and is referenced in a separate column. For this to work, the measure name field must be used in the column headers so the visual can establish context.

 

That said, this approach comes with limitations, most notably that the measure name column cannot be positioned between other columns, which can restrict layout flexibility.

danextian_0-1777902126343.pngdanextian_1-1777902140202.png

Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Shravan133
Super User
Super User

Instead of trying to toggle ascending/descending sorting, you convert everything into a single sorting column where the logic flips the sign when needed.

Step 1: Create a sort measure

Assume your main measure is: [MyMeasure]

Dynamic Sort Value =
VAR Dir = SELECTEDVALUE('Table'[Direction])
RETURN
    IF(
        Dir = "Up",
        [MyMeasure],          -- ascending behavior
        -[MyMeasure]          -- descending behavior
    )

Step 2: Use this in the tooltip table

In your tooltip table visual:

  • Keep displaying:
    • Dimension fields
    • [MyMeasure]
  • But sort by:
    • Dynamic Sort Value

Power BI always sorts ascending internally, but:

  • If values are normal → ascending sort = normal ascending
  • If values are negated → ascending sort = effectively descending

So:

  • Up → sort by real values
  • Down → sort by inverted values

Step 3: Set sorting

In the tooltip visual:

  1. Click the visual
  2. Sort by → Dynamic Sort Value
  3. Sort direction → Ascending (always)

 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.