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
saeidrasti
Frequent Visitor

calculate ratio when numerator changes by applying slicer and denominator is fixed

I have a dataset with two columns: range and mile. there is an slicer on the range which shows max range. I want to calculate the ratio of mile/total mile, for example when max range is 300 the ratio equals summation of miles for rows with range<=300 (600) over total mile (1700) which is 0.35. I would appreciate if you help me to do this. 

range mile 
300.00200
200.00100
500.00500
100.00300
1000.00600
 1700
  
range<=300ratio=0.352941
range<=100ratio=0.176471
1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

Try this: Tune to your needs

1) Table Name used as 'Q2 Table Ratio Slicer' and Slicer Name used as 'Slicer Range' (You can see the slicer name in view menu, show panes ... Selection, will get you the slicer name)

2) Measure used as

Measure Ratio based on Selected Slicer = 
var _allTotal = CALCULATE(sum('Q2 Table Ratio Slicer'[mile]), all('Q2 Table Ratio Slicer')) 
var _selSlicerMax = CALCULATE( MAX( 'Q2 Table Ratio Slicer'[range]), ALLSELECTED('Q2 Table Ratio Slicer'))
var _allValuesInRange = CALCULATE(sum('Q2 Table Ratio Slicer'[mile]), 
                            filter(all('Q2 Table Ratio Slicer'), 'Q2 Table Ratio Slicer'[range] <= _selSlicerMax)
                        )

RETURN Divide(_allValuesInRange, _allTotal, blank())

 

Formatted the measure as %

 

Output 1: <No selection>

sevenhills_0-1685470309493.png

Output 2: Selected: 300.00

sevenhills_1-1685470332599.png

 

Output 3: Selected: 100.00

sevenhills_2-1685470367644.png

 

Hope this helps!

 

View solution in original post

2 REPLIES 2
saeidrasti
Frequent Visitor

Thank you so much sevenhills. 

sevenhills
Super User
Super User

Try this: Tune to your needs

1) Table Name used as 'Q2 Table Ratio Slicer' and Slicer Name used as 'Slicer Range' (You can see the slicer name in view menu, show panes ... Selection, will get you the slicer name)

2) Measure used as

Measure Ratio based on Selected Slicer = 
var _allTotal = CALCULATE(sum('Q2 Table Ratio Slicer'[mile]), all('Q2 Table Ratio Slicer')) 
var _selSlicerMax = CALCULATE( MAX( 'Q2 Table Ratio Slicer'[range]), ALLSELECTED('Q2 Table Ratio Slicer'))
var _allValuesInRange = CALCULATE(sum('Q2 Table Ratio Slicer'[mile]), 
                            filter(all('Q2 Table Ratio Slicer'), 'Q2 Table Ratio Slicer'[range] <= _selSlicerMax)
                        )

RETURN Divide(_allValuesInRange, _allTotal, blank())

 

Formatted the measure as %

 

Output 1: <No selection>

sevenhills_0-1685470309493.png

Output 2: Selected: 300.00

sevenhills_1-1685470332599.png

 

Output 3: Selected: 100.00

sevenhills_2-1685470367644.png

 

Hope this helps!

 

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.