Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
This is what I need:
The sales amount % of items in the top 20 against the total sales. This must be dynamic, the top20 this week is different from the top20 last week.
So I create a measure:
[sales rank] = RANKX(ALLSELECTED('DIM-Item'),[Sales amt.])
this gets all items ranked based on the applied filters like week or item category.
Now I want to calculate the sales amount of the items with rank < 21
SUMX( FILTER('DIM-Item', [sales rank] < 21), [Sales amt.])
So far so good. Only items in the top20 (rank < 21) get a value in the table.
The problem is the total line.
The total line show the full sales amount. This is because the [sales rank] in the total line = 1. It does not filter the item lines and then summarizes. It calculates the formula on the total line and then the filter for [sales rank] < 21 is not correct.
Please check this table, especially the total line:
Thanks for the help
Kind regards,
Johan
Solved! Go to Solution.
Hi @Johan ,
The issue with your original measure is that the total row does not respect the row-level filtering of rank values. At the total level, DAX evaluates the expression as a whole rather than summing filtered individual rows. To fix this, you need to explicitly recreate the ranking per item within a row context and then filter based on that. This can be done using ADDCOLUMNS and RANKX over VALUES, which ensures the filter logic applies uniformly across all rows, including the total. Here’s the corrected DAX:
Top 20 Sales Amt =
SUMX(
FILTER(
ADDCOLUMNS(
VALUES('DIM-Item'[Item Code]),
"ItemRank", RANKX(ALLSELECTED('DIM-Item'[Item Code]), [Sales amt.])
),
[ItemRank] < 21
),
[Sales amt.]
)
This version creates a virtual table where each item code is ranked, filters to only the top 20, and then sums their sales amounts. This ensures the total row shows only the sum of sales for top 20 items, not the full total.
Best regards,
Hi @Johan , I wanted to check with you and see if the provided information was useful. If any of it helped resolve your question, consider marking it as "Accept as Solution" to make it easier for others to find. Let me know if there's anything else I can assist with!
Hi @Johan , Thank you for reaching out to the Microsoft Community Forum.
Based on your description, I took your sample data and worked out the solution.
Please refer attached .pbix file for reference and share your thoughts.
If this helped solve the issue, please consider marking it “Accept as Solution” so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.
Hi @Johan ,
The issue with your original measure is that the total row does not respect the row-level filtering of rank values. At the total level, DAX evaluates the expression as a whole rather than summing filtered individual rows. To fix this, you need to explicitly recreate the ranking per item within a row context and then filter based on that. This can be done using ADDCOLUMNS and RANKX over VALUES, which ensures the filter logic applies uniformly across all rows, including the total. Here’s the corrected DAX:
Top 20 Sales Amt =
SUMX(
FILTER(
ADDCOLUMNS(
VALUES('DIM-Item'[Item Code]),
"ItemRank", RANKX(ALLSELECTED('DIM-Item'[Item Code]), [Sales amt.])
),
[ItemRank] < 21
),
[Sales amt.]
)
This version creates a virtual table where each item code is ranked, filters to only the top 20, and then sums their sales amounts. This ensures the total row shows only the sum of sales for top 20 items, not the full total.
Best regards,
Thanks! That works. I know the concept of total level context, just couldn't work it out as you did.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
26 | |
10 | |
10 | |
9 | |
6 |