Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Show top n results by multiple categories

Hello, 

In my data I have many records for Date, Fund, Name and Total.

I need to show Top n by Date (newest to oldest), Fund (Alphabetical) and Total (sum) for each Name.

I put together a simple visual below and looking at Top 2.

 

Please help.

 

Form

DateFundNameTotal
5/31/2022SCA3
5/31/2022SCA5
5/31/2022SCD6
5/31/2022SCD7
5/31/2022SC3B2
5/31/2022SC3C4
6/30/2022SCA53
6/30/2022SCB44
6/30/2022SCC65
6/30/2022SCD22
6/30/2022SC3B63
6/30/2022SC3C2
7/31/2022SCA5
7/31/2022SCB8
7/31/2022SCA33
7/31/2022SC3A44
7/31/2022SC3B53
7/31/2022SC3C67

 

to

 

DateFundNameTotal
7/31/2022SCA38
7/31/2022SCB8
7/31/2022SC3C67
7/31/2022SC3B53
6/30/2022SCC65
6/30/2022SCA53
6/30/2022SC3B63
6/30/2022SC3C2
5/31/2022SCD13
5/31/2022SCA8
5/31/2022SC3C4
5/31/2022SC3B2
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@lbendlin lbendlin that did not work but here is what i did. it's tricky.

 

1. Add measure: TotalSum= SUM ( table [Total]) - From what i was told no naked calculations.

2. Add rank maeasure: Strategy Rank = RANKX( ALL( table [Name] ) , [TotalSum] )

3. The crazy measure: (I actually needed top 10, 2 was easier to use in an example)

Rank New =
Var _PerformRank =
IF (
ISBLANK( [TotalSum] ) , BLANK() ,
RANKX( ALL ( table[Name] ) , [TotalSum] , , ,Dense )
)
VAR _DisplayTop10 = IF (_PerformRank <=10 , _PerformRank , BLANK() )
VAR _DisplayAtNameLevel = IF ( ISINSCOPE( table[Name] ) , _DisplayTop10 , BLANK() )
RETURN
_DisplayAtNameLevel
4. I created a Reference table Fund with only unique Fund Names and joined it back with the original table.
TotalSum of Top 10 =
IF ( ISINSCOPE( Fund[Fund] ) ,
SUMX ( FILTER( VALUES( Name ) , [Rank New] <=10) , [TotalSum] ) , BLANK() )

 

That's pretty much it in the nutshel.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

You can do that in the Power BI user interface, without formulas. "Filters on this visual" allows you to switch to a TOPN type filter.  (Make sure to enable the setting to allow users of your report to change filter types)

Anonymous
Not applicable

Hi,

Top n will work if the names are repleating in all categories. That is not my case. You can see that D for example only shows up in one section.

Best.

create this measure

rn = rankx(calculatetable('Table',REMOVEFILTERS('Table'[Name])),CALCULATE(sum('Table'[Total])))

and then add it to the visual level filters and set it to "less than 3" 

 

lbendlin_0-1661812065800.png

 

Anonymous
Not applicable

@lbendlin lbendlin that did not work but here is what i did. it's tricky.

 

1. Add measure: TotalSum= SUM ( table [Total]) - From what i was told no naked calculations.

2. Add rank maeasure: Strategy Rank = RANKX( ALL( table [Name] ) , [TotalSum] )

3. The crazy measure: (I actually needed top 10, 2 was easier to use in an example)

Rank New =
Var _PerformRank =
IF (
ISBLANK( [TotalSum] ) , BLANK() ,
RANKX( ALL ( table[Name] ) , [TotalSum] , , ,Dense )
)
VAR _DisplayTop10 = IF (_PerformRank <=10 , _PerformRank , BLANK() )
VAR _DisplayAtNameLevel = IF ( ISINSCOPE( table[Name] ) , _DisplayTop10 , BLANK() )
RETURN
_DisplayAtNameLevel
4. I created a Reference table Fund with only unique Fund Names and joined it back with the original table.
TotalSum of Top 10 =
IF ( ISINSCOPE( Fund[Fund] ) ,
SUMX ( FILTER( VALUES( Name ) , [Rank New] <=10) , [TotalSum] ) , BLANK() )

 

That's pretty much it in the nutshel.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.