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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
barrymcguigan84
Frequent Visitor

Calculate Percentages of a Value

Hi, 

 

I need to calculate the percentages of each meal type out of the overall meals.  So if ice cream was 1 out of 2, it would be 50%.

 

I want my numerator to be all the values in the meal column regardless of a meal filter being applied (with all other filters such as date still working) and my denominator to be the filtered meal value.  

 

Could you advise me on a dax measure for this? 

 

IDDateMeal
43013-May-22Ice Cream
50924-May-22Ice Cream
60131-May-22Cake
67613-Jun-22Cake
78521-Jun-22Cake
89428-Jun-22Crisps
99606-Jul-22Ice Cream
99606-Jul-22Cake
104512-Jul-22Ice Cream
113419-Jul-22Ice Cream
116821-Jul-22Sweets
126828-Jul-22Ice Cream
146010-Aug-22Crisps
159822-Aug-22Cake
159822-Aug-22Cake
160022-Aug-22Crisps
160022-Aug-22Crisps
161923-Aug-22Sweets
161923-Aug-22Cake
161923-Aug-22Ice Cream
161923-Aug-22Ice Cream
163423-Aug-22Cake
164524-Aug-22Sweets
173031-Aug-22Cake
173431-Aug-22Cake
179206-Sep-22Cake
179206-Sep-22Sweets
179206-Sep-22Ice Cream
183309-Sep-22Cake
185713-Sep-22Ice Cream
185713-Sep-22Cake
189416-Sep-22Ice Cream
190316-Sep-22Cake
196423-Sep-22Cake
196423-Sep-22Cake
198727-Sep-22Cake
198727-Sep-22Sweets
204904-Oct-22Crisps
213912-Oct-22Cake
213912-Oct-22Crisps
219919-Oct-22Sweets
219919-Oct-22Sweets
221320-Oct-22Cake
221320-Oct-22Cake
221320-Oct-22Cake
221320-Oct-22Ice Cream
221320-Oct-22Cake
221320-Oct-22Sweets

 

 

Thank you in advance 

4 REPLIES 4
barrymcguigan84
Frequent Visitor

Thanks both, neither of these work for me unfortunately.  @Arul  I need to be able to see change over time, not the total percentages for all the values.  

 

@Padycosmos the measure works when I put it into a table or a matrix, the problem I have got is that when I put it into a line chart it works when all values are selected, but then when I select a particular value, it goes to 100% as the value is being filtered to that value.  Images below: 

 

 

barrymcguigan84_0-1676625224877.png

 

These percentages are correct but then if want to highlight one to see performance, this happens: 

 

barrymcguigan84_1-1676625289626.png

 

Is there a way to get it to work on whe selecting individual values? 

 

Hope this measure helps:

Count Pct = DIVIDE(CALCULATE(COUNT('Table'[Meal]),'Table'[Meal]=SELECTEDVALUE('Table'[Meal])),
CALCULATE(count('Table'[Meal]),ALL('Table'[Meal]))) 
Padycosmos_0-1676651366714.png

 

Padycosmos
Solution Sage
Solution Sage

Hope this helps:

Count Pct = DIVIDE(COUNT('Table'[Meal]),CALCULATE(COUNT('Table'[Meal]),ALLSELECTED('Table'[ID],'Table'[Meal])))
Padycosmos_0-1676582844189.png

Padycosmos_1-1676578796162.png

 


 

 
Arul
Super User
Super User

@barrymcguigan84 ,

try this code in measure,

Percentage of Meals = 
VAR _countOfMeals =  COUNT(YourTablename[Meal])
VAR _countOfAllMeals = CALCULATE(
                                COUNT(YourTablename[Meal]),
                                ALL(YourTablename)
                            )
VAR _result = DIVIDE(_countOfMeals,_countOfAllMeals)
RETURN _result

and then format measure as a percentage (refer the image attached),

Arul_0-1676568719322.png

Result:

Arul_1-1676568742854.png

Thanks,

Arul

 





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

Proud to be a Super User!


LinkedIn


Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors