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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Data_BS
New Member

Percentage of grand total problem

Hi community, 


I am trying to calculate the % of a grand total for a dimension column but with a slight twist. If a category's % of grand total is less than or equal to 10%, I'd like to bundle these categories into a group called "other" and the grand total of the "other" group should be the sum of their grand total %s.

I'd like the solution to be dynamic. For instance, I could select swap out different dimensions in a visual and this solution would work. Below is an example of what I'm trying to achieve. If anything is unclear, please shout. I'm open to any solution.

 

Example Data

Screenshot 2024-10-15 085920.png

Expected Output
Note, I've supplied two different tables in the solution. In PBI, I'd like just one table with the ability to pull the different dimensions into it.


Screenshot 2024-10-15 090435.png

 

Data used in problem

 

CountryFavourite ColourFlag
UKRed1
USARed1
FranceRed1
UKBlue1
UKBlack1
UKWhite1
GermanyGreen1
GermanyGreen1
GermanyBlue1
GermanyPink1

 

Thanks,

Ben

1 ACCEPTED SOLUTION
SamWiseOwl
Community Champion
Community Champion

Hi @Data_BS 

You need to Append a new row to the table with "Other" in both the country and the colour columns.

This is used to check which row we are on in the visual.

SamWiseOwl_0-1728984362289.png

Field Parameters: https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters

Let you swap which column is in the visual.

Create a measure:

Sales =
 var curr = CALCULATE(sum('Table'[Flag]))
 var total = CALCULATE(sum('Table'[Flag]),REMOVEFILTERS('Table'[Country],'Table'[Favourite Colour]))
 var per = curr/total
var sel = MAXX('Choose category',[Choose category])
 var colour = SUMMARIZE(ALLSELECTED('Table'),'Table'[Favourite Colour], "Percent",
  CALCULATE(sum('Table'[Flag]))/CALCULATE(sum('Table'[Flag]),REMOVEFILTERS('Table'[Country],'Table'[Favourite Colour])))
  var country = SUMMARIZE(ALLSELECTED('Table'),'Table'[Country], "Percent"
 ,CALCULATE(sum('Table'[Flag]))/CALCULATE(sum('Table'[Flag]),REMOVEFILTERS('Table'[Country],'Table'[Favourite Colour])))


var final =
SWITCH(
    TRUE()
    ,sel = "Country" && SELECTEDVALUE('Table'[Country]) = "Other"
    ,sumx(filter(country, [Percent] <=0.1), [Percent])
    ,SELECTEDVALUE('Table'[Favourite Colour]) = "Other"
    ,sumx(filter(colour, [Percent] <=0.1), [Percent])
    ,per <= 0.1
    ,BLANK()
    ,per)
return final
   
This tests if the selected item is Colour or Category, calculates which rows are below 10% and returns the appropriate calculation.
Hope this helps!
 

If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

View solution in original post

5 REPLIES 5
v-yajiewan-msft
Community Support
Community Support

Hi @Data_BS , hello ryan_mayu and SamWiseOwl, thank you for your prompt reply!

Is there any progress on this issue?

 

If you find any answer is helpful to you, please remember to accept it.

 

It will help others who meet the similar question in this forum.

 

Thank you for your understanding.

ryan_mayu
Super User
Super User

@Data_BS 

 

have you tried grouping and binning function?

 

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-grouping-and-binning?wt.mc_id=DP-M...

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ryan_mayu, this is really interesting. I didn't know about this. I'll check this out when I have time (currently at work so I can't). 

 

If this solves the problem, I'll let you know. 

 

Thanks for the navigation! 

SamWiseOwl
Community Champion
Community Champion

Hi @Data_BS 

You need to Append a new row to the table with "Other" in both the country and the colour columns.

This is used to check which row we are on in the visual.

SamWiseOwl_0-1728984362289.png

Field Parameters: https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters

Let you swap which column is in the visual.

Create a measure:

Sales =
 var curr = CALCULATE(sum('Table'[Flag]))
 var total = CALCULATE(sum('Table'[Flag]),REMOVEFILTERS('Table'[Country],'Table'[Favourite Colour]))
 var per = curr/total
var sel = MAXX('Choose category',[Choose category])
 var colour = SUMMARIZE(ALLSELECTED('Table'),'Table'[Favourite Colour], "Percent",
  CALCULATE(sum('Table'[Flag]))/CALCULATE(sum('Table'[Flag]),REMOVEFILTERS('Table'[Country],'Table'[Favourite Colour])))
  var country = SUMMARIZE(ALLSELECTED('Table'),'Table'[Country], "Percent"
 ,CALCULATE(sum('Table'[Flag]))/CALCULATE(sum('Table'[Flag]),REMOVEFILTERS('Table'[Country],'Table'[Favourite Colour])))


var final =
SWITCH(
    TRUE()
    ,sel = "Country" && SELECTEDVALUE('Table'[Country]) = "Other"
    ,sumx(filter(country, [Percent] <=0.1), [Percent])
    ,SELECTEDVALUE('Table'[Favourite Colour]) = "Other"
    ,sumx(filter(colour, [Percent] <=0.1), [Percent])
    ,per <= 0.1
    ,BLANK()
    ,per)
return final
   
This tests if the selected item is Colour or Category, calculates which rows are below 10% and returns the appropriate calculation.
Hope this helps!
 

If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Hi @SamWiseOwl. I'm at work at the moment but I'll explore this as soon as I get time. Thanks for providing this, I'll keep you updated. Absolute legend. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.