Forum Discussion
Calculating SUM of TOPN rows
- 10 years ago
Hi BogdanP. Here's how I modified your TopVolume formula to get it to work with some made up data:
TopVolume = CALCULATE(
SUMX(VALUES(Producers[Producer Eng]), [VolumeSum]),
FILTER(ALL(Producers[Producer Eng]), [VolumeRanks2]<=[Selected TopN])
)And a screenshot of it in action:
Hopefully this works for your model. If not, please include some sample data. I know enough about DAX to figure it out, but it takes some puzzling first. I'll give an explanation a shot, and a more seasoned pro can correct or add more if needed :)
As it was, there was nothing in the formula to summarize the values at the Producer Eng level, which made the rank of no real effect within the formula. Essentially, you got the sum of Volumes for everyone, because every row was evaluated against itself and got a rank of 1.
Adding in the SUMX tells the formula that we want to first get the VolumeSum amounts for each Producer Eng, then rank them at that level and determine if the rank is less than or equal to the Selected TopN.
This article is where I got my start with SUMX. It's a bit dated, but I still refer to it for a simple breakdown.
You'll also notice I changed the FILTER context from using the Volumes table to the ALL(Producers[Producers Eng]) column. Because RANKX is working on that column, it's what we need to include all of for the RANKX to function like we want.
Thank you KGrice so much for such a detailed answer! I suspected that the problem lies exactly in evaluating rows all by itself, however, i went wrong way trying to use SUMMARIZE by [Producer Eng]. I've even tried SUMX but never used VALUES.
I am quite new to DAX and PowerBI and I will definitely dig more into basics like SUMX, AVERAGEX etc to avoid bothering people with dumb questions:)
Thank you once again!