Top N values category wise in Power BI

Today we’ll be learning how to show Top N values Category wise in Power BI. The tutorial will be very useful in many context. 2 steps solution it is and I’ve attached the pbix file to download and reuse.

Data

So I’ve data in the following format and I want to show Top 3 subtypes based on values for each type.

TypeSubtypeValue
aa11
aa22
aa33
aa44
aa55
bb16
bb27
bb38
bb49
bb510
cc111
cc212
cc313
cc414
cc515

Step 1 : Measure for values

Sales = CALCULATE(SUM('Table'[Value]))

Step 2 : TOP N measure

FilterTop3ByCat_Filter =
VAR Top3Cat =
CALCULATETABLE (
GENERATE (
VALUES ( 'Table'[Type]),
TOPN (
3, // instead of 3 you can use any number, currently showing top 3
CALCULATETABLE ( VALUES ( 'Table'[Subtype] ) ),
[sales]
)
),
ALLSELECTED()
)
RETURN
CALCULATE (
1 * ( NOT ISEMPTY ( 'Table') ),
KEEPFILTERS ( Top3Cat )
)

Download Power BI File

Keep visiting Analytics Tuts for more tutorials.

Thanks for reading! Comment your suggestions and queries


Leave a Reply

Your email address will not be published. Required fields are marked *