PDA

View Full Version : TOPN function



Spencer_2
2017-02-02, 08:50 PM
What is correct syntax to SUM all items sales that comprise top 5(n)? I've tried numerous examples SUMX, Summarize, etc. Still no luck.



Thanks,

Spence

Owen Auger
2017-02-12, 12:00 PM
Hi Spence,

In case you're still looking for a solution, here a few variations of a TopN-type measure using the TOPN function to define the filter, depending on the behaviour you want. These don't cover every possibility but should get you started.

I've assumed that you have a [Sales] measure defined and your Item column is Sales[Item].


Sales Top 5 Items In Current Context =
CALCULATE ( [Sales], TOPN ( 5, VALUES ( Sales[Item] ), [Sales] ) )


Sales Top 5 Items Regardless of Item Filter =
CALCULATE ( [Sales], TOPN ( 5, ALL ( Sales[Item] ), [Sales] ) )


Sales Top 5 Items Intersecting with Current Context =
CALCULATE (
[Sales],
TOPN ( 5, ALL ( Sales[Item] ), [Sales] ),
VALUES ( Sales[Item] )
)

Spencer_2
2017-02-13, 10:20 PM
Owen... Worked perfectly. Exactly what I needed. Also appreciate the other variations. These will come in SOOOO handy.

Best,
Spencer