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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
uif19085
Helper III
Helper III

Calculate Dynamic Ratios

Trying to find a way to change a ratio calculation with slicer which is having values from a column. 
For example: i have 3 values in a column: apples, pears, oranges and another column where i found which from these fruits are eaten or not, flaged with 1/0.
I want a slicer to select the fruit and get the ratio of that eaten fruit out of total. Total ratio of eaten apples is calculated like this: Total number of eaten apples / Total number of apples. From the slicer i want to change this calculation dynamically for each fruit. 
 

uif19085_0-1679924500691.png

 

1 ACCEPTED SOLUTION
Arul
Super User
Super User

@uif19085 ,

try this in measure,

Ratio of eaten fruit =
VAR _eaten =
    CALCULATE ( COUNT ( Table[Fruits] ), Table[Flag] = 1 )
VAR _all =
    CALCULATE ( COUNT ( Table[Fruits] ), ALL ( Table) )
VAR _result =
    DIVIDE ( _eaten, _all )
RETURN
    _result

Thanks,

Arul





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

Proud to be a Super User!


LinkedIn


View solution in original post

7 REPLIES 7
uif19085
Helper III
Helper III

Hello @Arul , Thank you for your answer. Doesn't seem to work. The result should be 3.76% 

uif19085_1-1679992455721.png

 

@uif19085 ,

Can you show me the formula what you have use for measure?

Thanks,

Arul





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

Proud to be a Super User!


LinkedIn


@Arul 
Sure, but i have to show you the real data tables i use:

Automated Ratio =
VAR Auto = CALCULATE(COUNT(Artefact[Requirements Selection]), Artefact[Automated] = 1)
VAR _all = CALCULATE(COUNT( Artefact[Requirements Selection]), ALL(Artefact))
VAR _result = auto/_all
RETURN
_result
I have a Slicer for Requirement Selection and I marked with 1 which from these are automated

@uif19085 ,

I am not sure about the problem. But, Can you multiply the result with 100 and see?

Thanks,

Arul





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

Proud to be a Super User!


LinkedIn


@Arul I've debug a little, and the _all variable doesn't work as intended, it should filter by the slicer value, i've got 1M results for it and the result doesn't change from the slicer , should be 5857

I've done it. I change _all variable with "

CALCULATE(COUNT( Artefact[Requirements Selection]))
)" Thanks for your help, i will still accept your input. 
Arul
Super User
Super User

@uif19085 ,

try this in measure,

Ratio of eaten fruit =
VAR _eaten =
    CALCULATE ( COUNT ( Table[Fruits] ), Table[Flag] = 1 )
VAR _all =
    CALCULATE ( COUNT ( Table[Fruits] ), ALL ( Table) )
VAR _result =
    DIVIDE ( _eaten, _all )
RETURN
    _result

Thanks,

Arul





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

Proud to be a Super User!


LinkedIn


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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