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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ToddChitt
Super User
Super User

RANKX with Slicers

I'm having a little trouble with the RANKX function and Slicers. I'm uder the impression that when you select one or more members from a slicer on a report page, that the data available to visuals on the page is thereby filtered. Such does not apply if you display a measure that, by its definition, includes a larger or different set of data.

Here is what I have:

  • A Sales Table, with column [Line Item Total]
  • Sales table related to Item table on Item ID
  • Vendor table related to Item table on Vendor ID
  • A Calculated Column in the Vendor table: Vendor Ranking = RANKX( 'Vendors', SUMX(RELATEDTABLE('Sales'), [Line Item Total]))
  • A Customer table related to Sales table on Customer ID

When I use a table visual, and include Vendor Name, Sum of [Line Item Total], and Vendor Ranking, with no slicer, everything looks good. Sort by Sum of Line Item Total and you see that the Vendor that had the most sales of their items is at the top and ranked 1, next guy is ranked 2 and so on. Looks good.

 

Now, I add a slicer to the page and select one single Customer. The Vendors, still sorted by Sum of Line Item Total are now ranked 1, 9, 5, 3, 4 etc. NOT 1, 2, 3...

I have also tried the following formulas for the RANKX function:

 

  • RANKX(ALL('Vendors'), SUMX(RELATEDTABLE('Sales'), [Line Item Total]))
  • RANKX(ALLSELECTED('Vendors'), SUMX(RELATEDTABLE('Sales'), [Line Item Total]))

Also treid variation of the SUMX, replacing it with a pre-summed measure from the Sales table

[Sum Line Item Total] = SUM[Line Item Total]

 

Ultimately, the filtered list of Customers available to the user will be driven by Row Level Security, but I need to get this working with a Customer slicer then I know RLS will be accurate.

 

What am I missing?

 

Thanks in advance.

 




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





1 ACCEPTED SOLUTION
ankitpatira
Community Champion
Community Champion

@ToddChitt Check out this post. Use some of the code provided maybe last one will be useful.

View solution in original post

2 REPLIES 2
ankitpatira
Community Champion
Community Champion

@ToddChitt Check out this post. Use some of the code provided maybe last one will be useful.

@ankitpatira:

I had come across that article before, and thought I was doing everything correctls. Obvously not, hence this post. The key phrase word character in that post that finally light the lamp for me was the colon : . Those two simple dots stacked vertically.

 

You see, for those of you who may not be familiar with the Excel version of DAX, the syntax for Calculated Measure was this:

Measure := <some definition>

And this is the syntax used in the post authored by Rob Collie,

 

Now, in Power BI, the syntax has been relaxed a little to this:

Measure = <some definition>

 

But, the syntax is the same for Columns:

Column =<some definition>

 

That colon sparked my brain to realize I needed to be creating my Ranking as a MEASURE, not a COLUMN. Same definition, different results.

 

Thanks Ankit, Thanks Rob.

FYI, I settled on a (measure) Ranking as follows:

Measure = RANKX ( ALLSELECTED ( 'Vendors' ), SUMX ( RELATEDTABLE ( 'Sales' ), [Sum Line Item Total] ) )




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.