March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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.
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.
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):
Medium | Small | Overall | |
DEALSIZE | Ranks States Sales-Delta | Ranks States Sales-Delta | Ranks States Sales-Delta |
CT | 6 | 7 | |
PA | 5 | 6 | 6 |
Victoria | 7 | 4 | 5 |
NSW | 4 | 5 | 4 |
NY | 3 | 3 | 3 |
MA | 2 | 2 | 2 |
CA | 1 | 1 | 1 |
Total | 1 | 1 | 1 |
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,
Solved! Go to Solution.
Hi,
PBI file attached.
Thank you Ashish, this appears to be what I needed and I appreciate it immensely.
You are welcome.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
85 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |