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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
TremoloTremblin
Regular Visitor

RANKX Measure failing to return correct results after a slicer and visual filter is applied

Sharing a sample project to explain the problem 

I have a matrix  where I need to rank States by a metric called MSRP Delta (The difference between SALES and MSRP) in descending order. The rankings (among other measures brought back) are broken down by the column "DEALSIZE" so there'll be measure summaries for each and a final Row Total at the end. 

The measure is calculated as: 

MSRP Delta = SUM(sales_data_sample[SALES]) - sum(sales_data_sample[MSRP])

I'm using a Top N Parameter table with GENERATESERIES and have placed this value into a slicer. When the user selects the 'N' value in a slicer, a measure only return rankings of MSRP Delta by State that are less than or equal to the value N. This can be seen in this main function:

Rank States Sales-Delta Top N =
Var _topN = SELECTEDVALUE('Top N Parameter'[Value])
RETURN SWITCH(TRUE(), RANKX(ALLSELECTED(sales_data_sample[STATE]),CALCULATE([MSRP Delta]),,DESC,Dense)  <= _topN,RANKX(ALLSELECTED(sales_data_sample[STATE]),CALCULATE([MSRP Delta]),,DESC,Dense),BLANK())

Finally, to only return matrix values that meet this criteria, I have the visual filter "Filter out blank values" set so any non-ranked STATES are removed. 

 

Initially, it appears that the calculation returns roughly what i want in a matrix overall before applying the visual filter; for example when I set 'N=7' and have a slicer on the 'Status' column active. The column break downs are producing false ties and skipped ranks but the overall score appears correct. 

TremoloTremblin_0-1721435800426.png

 

However, when I apply the visual filter to remove blanks I get the following table. With Top N = 7, it's now missing the 7th place value and again producing incorrect duplicate rankings for the column breakdowns.

 

TremoloTremblin_1-1721436018052.png

 

I need to fix the filter context of this calculation to avoid these silly results being returned and to bring back the correct amount of unique rows for any Top N selected. So if I keep N=7 and my slicers selected, it should return the top 7 based on overall row total only, remove false ties, avoid rank skips and ignore rows such as BC which are non-ranked overall.So a table output of that description should look like (ignoring other measures to be brought back): 

 

 MediumSmallOverall
DEALSIZERanks States Sales-DeltaRanks States Sales-DeltaRanks States Sales-Delta

CT

6 7
PA566
Victoria745
NSW454
NY333
MA222
CA111
Total111

 

I just can't wrap my head around where I'm going wrong in the filter context - it's probably something really easy but I've spent forever tweaking and the result largely comes up the same. Can someone please help me understand where I'm going wrong with this?  

 

Here's a sample PBIX that covers the above scenario and provides all relevant visuals, measures and associated fields: https://drive.google.com/file/d/1mOPZ1a5Bi_KY5L88K0drYFrmMPoUs0E_/view?usp=drive_link

 

Regards, 

 

 

 

 

 


 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Ashish_Mathur_0-1721443712319.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Ashish_Mathur_0-1721443712319.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you Ashish, this appears to be what I needed and I appreciate it immensely. 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.