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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
pshah
Regular Visitor

Show Top N and sum up the Others as a value

I created a Rank column and a custom measure. I've filtered on Rank to show less than 11, so basically show me the top 10.

The custom measure is basically saying to show me when rank <= 5, then show Amount else Others.

 

Instead of "Others", is there a way to sum up the Amount value and end up only showing 6 rows. First 5 rows shows the top 5 countries, and then the 6th row sums up the countries that are ranked from 6 to 10.

 

2017-11-28_11-25-53.png

1 ACCEPTED SOLUTION

Here is the solution:

 

1. Goto modelling tab and click new table and add following dax :

 

 

Country with other = UNION(Values('Dim - Country'[Country Name]), ROW("Country Name", "Others"))

it will create a new table with all the countries and addition country "Others"

 

2. Set relationship with this new country with your original table (it will be 1 to many)

 

3. change your country rank measure like this 

 

Ctry Rank = RANKX(ALL('Country with others'[Country Name]), 'Dim - Country'[Total])

4. Add new measure "Total with other" -> This is final measure we need

 

Total with other = 
if([Ctry Rank] <= 10, 'Dim - Country'[Total],
	if(HASONEVALUE('Country with others'[Country Name]), 
		if(values('Country with others'[Country Name]) = "Others", 
			sumx(filter(all('Country with others'[Country Name]), [Ctry Rank ] > 10),  'Dim - Country'[Total])
		)
	)
)

5. Add new table visual , drop country name from "Country with other table" and Total with other measure

 

I expect that you will top 10 countries with their value and rest should be all summed up with "Others"

 

PS - There could be typo in DAX expression, let me know if it doesn't work



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

15 REPLIES 15
barrybilewitz
Frequent Visitor

I adapted your formulae for media sales and it worked like a charm - thank you.

@barrybilewitz glad to hear



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Phil_Seamark
Employee
Employee

HI @pshah

 

Is your City Rank a calculated measure or a calculated column?  Can you please share the code you used for this.

 

For the 6th row, what you like to see in the 2nd and 3rd columns?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Calculated measure -> Ctry Rank = RANKX(ALL('Dim - Country'[Country Name]), 'Dim - Country'[Total])

 

For the 6th row, I'd like to see "Others" in the 2nd and 3rd column, if that makes sense.

pshah
Regular Visitor

For the 4th column, I'd like to show the remaining amount on the 6th row.

 

Based on the screen shot, the math will come out to a little under 50m. So I'd like to show that amount / value in the 4th column and 6th row.

Here is the solution:

 

1. Goto modelling tab and click new table and add following dax :

 

 

Country with other = UNION(Values('Dim - Country'[Country Name]), ROW("Country Name", "Others"))

it will create a new table with all the countries and addition country "Others"

 

2. Set relationship with this new country with your original table (it will be 1 to many)

 

3. change your country rank measure like this 

 

Ctry Rank = RANKX(ALL('Country with others'[Country Name]), 'Dim - Country'[Total])

4. Add new measure "Total with other" -> This is final measure we need

 

Total with other = 
if([Ctry Rank] <= 10, 'Dim - Country'[Total],
	if(HASONEVALUE('Country with others'[Country Name]), 
		if(values('Country with others'[Country Name]) = "Others", 
			sumx(filter(all('Country with others'[Country Name]), [Ctry Rank ] > 10),  'Dim - Country'[Total])
		)
	)
)

5. Add new table visual , drop country name from "Country with other table" and Total with other measure

 

I expect that you will top 10 countries with their value and rest should be all summed up with "Others"

 

PS - There could be typo in DAX expression, let me know if it doesn't work



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

didnt like

if([Ctry Rank] <= 10, 'Dim - Country'[Total],

 the expression... i added sumx as pref but also not accepted... any ideas ?

Anonymous
Not applicable

Hallo @parry2k ,

your solution almost worked for me as well.

 

But I still don´t get the solution I need.

 

Top10Products.png

I get my Top 10 Products and the Rest (Sonstige), but sum is just the sum of Top 10 Products. But it should be round about 43 Millions.

I just changed the first measure, instead of Values I used Distinct. With Values I get circular dependencies.

 

All other measures like your measures.

 

I am thankfull for every help!

Christian

 

 

Can you please let me know how have got the column in Total with Other Measure after If condition.

if([rank]>10, table[cloumn name].

This is not right syntax right. Can you please correct me.

I Have 2 Columsn Products and sales. I want to get Top 5 rows  Dynamically and rest 5 as sum value in a single row. Can you please help me achive this. I was trying out the Steps but could not get it done.

ProductSales
A3
B4
C1
D5
E7
F8
G12
H9
I2
K10
Anonymous
Not applicable

Hi  Parry2K 

 

 

 

 

 

 

 

 

Thank you!! I'll try this, currently in DirectQuery mode so will have to Import. 

 

Will let you know if it worked or not.

Sounds good. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

hi Parry,

 

I have a similar issue which i couldnt figure out.

 

I also wanted to as a 11th row to my list which i filter by the "filter on the visiual"

 

the ranx formula on the filter is :

 

 

Rank320EksiHesaplar = RANKX(ALLSELECTED('Mizan Özet'[Hesap No]),CALCULATE( sum('Mizan Özet'[Toplam]),'Mizan Full'[Hesap Grubu] = "320"),,1)

 

 

umutkoyun_1-1655703143326.png

 

 

I tried with summarizecolumns but it didnt work.

 

 

 

Measure2 = 

var Rank320 = RANKX(ALLSELECTED('Mizan Özet'[Hesap No]),
              CALCULATE( sum('Mizan Özet'[Toplam]),
              filter(ALLSELECTED('Mizan Özet'),'Mizan Özet'[Hesap Grubu] = "320"),
              filter(ALLSELECTED('Mizan Özet'),'Mizan Özet'[Toplam] < 0)
              )
              ,,1)

 var rr = SUMMARIZECOLUMNS(
     
     'Mizan Özet'[Firma Adı], 
     "Toplam", 
            IF (
                (RANKX(ALLSELECTED('Mizan Özet'[Hesap No]),
              CALCULATE( sum('Mizan Özet'[Toplam]),
              filter(ALLSELECTED('Mizan Özet'),'Mizan Özet'[Hesap Grubu] = "320"),
              filter(ALLSELECTED('Mizan Özet'),'Mizan Özet'[Toplam] < 0)
              )
              ,,1))>10,sum('Mizan Özet'[Toplam]),0)
 )
 
return 
rr

 

 

I started to adapt the first step of your solution. I used distinct but it didnt solve the problem with the 1-many relationship. It gives many-many relation somehow which seems not right.

320 Diğer Borçlar = union(DISTINCT('Mizan Özet'[Hesap No]),row("Hesap No", "320 Diğer Borçlar"))

 

thanks for your time....

Sorry for the very late reply but it worked! Thank you very much for the help!!!!

Helpful resources

Announcements
March Fabric Community Update

Fabric Community Update - March 2024

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

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.