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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
mmcblues
New Member

Dynamic quartile calculations using measures

Refer the below dataset, I need to calculate or categorize the value field below in to quartiles. I have a Category slicer in the report , which is a multiselect slicer and when i select a category, the quartile calculation should recalculate.

 

CategoryGenderIDValue
AM148
AF229
AM339
AM412
AM512
AF639
BF725
BF824
BM921
BM1014
BF1139
CM1213
CM1346
CM1437
CM1534
CF1647
CF1714
CM1817
CM1927
CM2014

Just to updatethe question, 

am using a measure like below

Quartile_Num =

VAR Weights = SUMMARIZE ( ALLSELECTED(TESTDATA), TESTDATA[ID], "Metric",Sum([Value])

VAR UQ1 =PERCENTILEX.INC(Weights, [Metric], 0.25)
VAR UQ2 = PERCENTILEX.INC(Weights, [Metric], 0.50)
VAR UQ3 = PERCENTILEX.INC(Weights, [Metric], 0.75)

VAR CurrW = CALCULATE(Sum([Value])

RETURN
SWITCH (
TRUE (),
CurrW <= UQ1, "Q1",
CurrW > UQ1 && CurrW <= UQ2, "Q2",
CurrW > UQ2 && CurrW <= UQ3, "Q3",
"Q4"
)
 
along with this, am using a disconnected table for Quartile labels.
the issue i have is when i was calculating count for each gender, the percentile calculation is getting recalculated based on that filter and i dont want that. i have only one slicer in my report, that is for category. i want only that filter to affect the percentile calculation.
 
Current Result
mmcblues_1-1630565044013.png

Expected Result as per excel

mmcblues_2-1630565087736.png



1 ACCEPTED SOLUTION
mmcblues
New Member

I was able to resolve the issue by using below measure.

 

Count of employees =
var _p1=CALCULATE(PERCENTILE.INC(TESTDATA[Value],0.25),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
var _p2=CALCULATE(PERCENTILE.INC(TESTDATA[Value],0.5),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
var _p3=CALCULATE(PERCENTILE.INC(TESTDATA[Value],0.75),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
var _p4=CALCULATE(PERCENTILE.INC(TESTDATA[Value],1),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
return SWITCH(SELECTEDVALUE(QuartileLabel[Label]),
"Q1",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]<=_p1)),
"Q2",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]>_p1 && TESTDATA[Value]<=_p2)),
"Q3",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]>_p2&& TESTDATA[Value]<=_p3)),
"Q4",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]>_p3&& TESTDATA[Value]<=_p4)))
 
 

View solution in original post

5 REPLIES 5
mmcblues
New Member

I was able to resolve the issue by using below measure.

 

Count of employees =
var _p1=CALCULATE(PERCENTILE.INC(TESTDATA[Value],0.25),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
var _p2=CALCULATE(PERCENTILE.INC(TESTDATA[Value],0.5),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
var _p3=CALCULATE(PERCENTILE.INC(TESTDATA[Value],0.75),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
var _p4=CALCULATE(PERCENTILE.INC(TESTDATA[Value],1),ALLEXCEPT(TESTDATA,TESTDATA[Value],TESTDATA[Category]))
return SWITCH(SELECTEDVALUE(QuartileLabel[Label]),
"Q1",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]<=_p1)),
"Q2",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]>_p1 && TESTDATA[Value]<=_p2)),
"Q3",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]>_p2&& TESTDATA[Value]<=_p3)),
"Q4",CALCULATE(DISTINCTCOUNT(TESTDATA[ID]),FILTER(TESTDATA,TESTDATA[Value]>_p3&& TESTDATA[Value]<=_p4)))
 
 
Anonymous
Not applicable

Hi @mmcblues,

AFAIK, you can use measure expression to interact with filter selection and return category tags based on current value, but measures cannot be used on axis or legend fields. (current they only support columns)
For this scenario, I'd like to suggest you use table visuals instead to show the record with measure expression results of categories.

BTW, calculated column/table formulas are not able to dynamically change based on slicer/filters. (they are working on different data levels and you can't use child level to affect its parent)

Notice: the data level of power bi.

Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

CategoryGenderIDValue
AM148
AF229
AM339
AM412
AM512
AF639
BF725
BF824
BM921
BM1014
BF1139
CM1213
CM1346
CM1437
CM1534
CF1647
CF1714
CM1817
CM1927
CM2014

Just to update you, i have gone through the links that you posted but its not getting what i wanted.

am using a measure like below

Quartile_Num =

VAR Weights = SUMMARIZE ( ALLSELECTED(TESTDATA), TESTDATA[ID], "Metric",Sum([Value])

VAR UQ1 =PERCENTILEX.INC(Weights, [Metric], 0.25)
VAR UQ2 = PERCENTILEX.INC(Weights, [Metric], 0.50)
VAR UQ3 = PERCENTILEX.INC(Weights, [Metric], 0.75)

VAR CurrW = CALCULATE(Sum([Value])

RETURN
SWITCH (
TRUE (),
CurrW <= UQ1, "Q1",
CurrW > UQ1 && CurrW <= UQ2, "Q2",
CurrW > UQ2 && CurrW <= UQ3, "Q3",
"Q4"
)
 
along with this, am using a disconnected table for Quartile labels.
the issue i have is when i was calculating count for each gender, the percentile calculation is getting recalculated based on that filter and i dont want that. i have only one slicer in my report, that is for category. i want only that filter to affect the percentile calculation
Anonymous
Not applicable

Hi @mmcblues,

You can take a look at the following blog about all functions to use them ignore the particular filter effects.

Managing “all” functions in DAX: ALL, ALLSELECTED, ALLNOBLANKROW, ALLEXCEPT - SQLBI
Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors