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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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