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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Top N, others and null values

Hi,

 

I am no PowerBI expert. I have read multiple topics on this issue and have been trying things out for hours, but I still haven't reach the desired outcome.

 

I have created a test file, see the link below. I would like to have a top 3 "Product" based on the "Sales" numbers. The rest of the products must be combined in an "Others" category.

 

Now here is the catch. When you open the data you will see that the "Product" with the most amount of "Sales" has a null value. By default I would like to add this null value in the "Others" category. So since the null value "Product" is excluded in the ranking the top 3 actually contains the top 2 t/m 4. When for example the null value is on position 3 in the top 3 (when only filtering the year 2018) the top 3 actually contains product 1, 2 and 4.

 

I hope my question is clear!

 

Top 3.pbix 

 

Thanks in advance!

 

Rotjer

9 REPLIES 9
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Create a measure as below:

Measure = 
var _sumtotal=SUMX(FILTER(ALL(Data),'Data'[Product]=MAX('Data'[Product])&&'Data'[Year]=MAX('Data'[Year])&&'Data'[Product]<>BLANK()),'Data'[Sales])
var _top=TOPN(3,FILTER('Data','Data'[Product]<>BLANK()),_sumtotal,DESC)
Return
SUMX(_top,'Data'[Sales])

Then put the measure in the filter pane ,choose top 3:

Annotation 2020-07-30 152412.png

And you will see:

Annotation 2020-07-30 152455.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Anonymous
Not applicable

Hi @v-kelly-msft ,

 

Thanks for your respons! This indeed fixed the issue with the blank "Product". The only thing missing is the "Others" category including the blank "Product".

 

Best regards,

Rotjer

Hi  @Anonymous ,

 

So you want the blank rows to be grouped as "others",then be ranked in order,right?

If so ,first create a new column as below:

Product new = IF('Data'[Product]=BLANK(),"others",'Data'[Product])

Then create a measure as below;

Measure = 
var _sumtotal=SUMX(FILTER(ALL(Data),'Data'[Product new]=MAX('Data'[Product new])&&'Data'[Year]=MAX('Data'[Year])),'Data'[Sales])
var _top=TOPN(3,'Data',_sumtotal,DESC)
Return
SUMX(_top,'Data'[Sales])

You will see:

Annotation 2020-07-31 092918.png

For the updated .pbix file,pls see attached.

 

 
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Anonymous
Not applicable

Hi @v-kelly-msft,

 

Thanks for your time!

I actually want a top 3 category with an extra "others" category. The "others" category contains the blank rows and the other rows which didn't make the top 3. So basically the totals will always be the same but the grouping will be different.
See the result that I want below:

 

Current:

Product

Sales

 

920

D

890

C

785

B

760

E

730

A

705

Totals

4790

 

New:

Product

Sales

D

890

C

785

B

760

others

2355

Totals

4790

 

Kind regards,

Rotjer

Anonymous
Not applicable

Can anyone help me with this problem?

amitchandak
Super User
Super User

@Anonymous , refer if this can help

https://community.powerbi.com/t5/Desktop/RANKX-excluding-blanks/m-p/397656#M181491

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak,

 

I indeed already seen that post, but it wasn't helpful enough for me. Like I said I'm not a pro. The difference with my situation is that my "Category" (Club) is blank and not the values (YOY).

@Anonymous ,Can you share sample data and sample output in table format? 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak Can you download Top3.pbix in my first post?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.