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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
andy_pat
Helper I
Helper I

Quartile Calculation Based on Measure

Hi- I am trying to calculate the quartile boundaries of the aggregated and filtered data set. However, I don't seem to be getting my measures calculation right. 

Could someone please help understand how to correct either of these measures, so they calculate correct quartiles based on filters.
Test file attached here 

 

Expected result based on excel PERCENTILE.INC calculation of 
2

5

4

7

3.54.55.57
Q1Q2Q3Q4


but I get the following both of which are incorrect:

categoryTotal ScoreQuartile MedianQuart using Summary
a222
b555
d454
c7Q47


Measure code: 

 

 

 

Quart Summary = 
VAR Sales =
    SUM ( 'Table'[score])
VAR Calls =
    SUMMARIZE('Table'
      , 'Table'[category]  
      , "total", Sales)        
      
var q1 = PERCENTILEX.INC(Calls,Sales, 0.25)
var q2 = PERCENTILEX.INC(Calls,Sales, 0.5)
var q3 = PERCENTILEX.INC(Calls,Sales, 0.75)
var q4 = PERCENTILEX.INC(Calls,Sales, 1)

RETURN
    // SUMX(calls,[Val])
    SWITCH( 
        TRUE(),
        Sales >= 0 &&  Sales <= q1 ,q1,
        Sales > q1 && Sales <= q2 ,q2,
        Sales > q2 && Sales  <= q3 ,q3,
        "Q4"
    )
Quartile Median = 
VAR Sales =
    SUM ( 'Table'[score] )
VAR List =
    GROUPBY (
        ALL ( 'Table' ),
        // 'Table'[category],'Table'[Zone],
        'Table'[category],
        "Val", SUMX ( CURRENTGROUP (), [score] )
    )
VAR Pct50 =
    MEDIANX ( List, [Val] )
VAR Pct75 =
    MEDIANX ( FILTER ( List, [Val] >= Pct50 ), [Val] )
VAR Pct25 =
    MEDIANX ( FILTER ( List, [Val] < Pct50 ), [Val] )
RETURN
if(Sales <> BLANK(),
    SWITCH( 
        TRUE(),
        Sales >= 0 && Sales <= Pct25 ,Pct25,
        Sales > Pct25 && Sales <= Pct50 ,Pct50,
        Sales > Pct50 && Sales  <= Pct75, Pct75,
        "Q4"
    ))

 

 

 

 

Thanks in advance!
Andy

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @andy_pat 

 

Is it what you want?

 

Vera_33_0-1616485041521.png

Quart Summary = 
VAR Sales =
    SUM ( 'Table'[score])
VAR Calls =
   GROUPBY(ALLSELECTED('Table')
      , 'Table'[category]  
      , "total",  SUMX (CURRENTGROUP(), 'Table'[score]))    
     
var q1 = CALCULATE(PERCENTILEX.INC(Calls,[total], 0.25),ALL('Table'))
var q2 = CALCULATE(PERCENTILEX.INC(Calls,[total], 0.5),ALL('Table'))
var q3 = CALCULATE(PERCENTILEX.INC(Calls,[total], 0.75),ALL('Table'))
var q4 = CALCULATE(PERCENTILEX.INC(Calls,[total], 1),ALL('Table'))

RETURN
    // SUMX(calls,[Val])
    SWITCH( 
        TRUE(),
        Sales >= 0 &&  Sales <= q1 ,q1,
        Sales > q1 && Sales <= q2 ,q2,
        Sales > q2 && Sales  <= q3 ,q3,
        "Q4"
    )

View solution in original post

1 REPLY 1
Vera_33
Resident Rockstar
Resident Rockstar

Hi @andy_pat 

 

Is it what you want?

 

Vera_33_0-1616485041521.png

Quart Summary = 
VAR Sales =
    SUM ( 'Table'[score])
VAR Calls =
   GROUPBY(ALLSELECTED('Table')
      , 'Table'[category]  
      , "total",  SUMX (CURRENTGROUP(), 'Table'[score]))    
     
var q1 = CALCULATE(PERCENTILEX.INC(Calls,[total], 0.25),ALL('Table'))
var q2 = CALCULATE(PERCENTILEX.INC(Calls,[total], 0.5),ALL('Table'))
var q3 = CALCULATE(PERCENTILEX.INC(Calls,[total], 0.75),ALL('Table'))
var q4 = CALCULATE(PERCENTILEX.INC(Calls,[total], 1),ALL('Table'))

RETURN
    // SUMX(calls,[Val])
    SWITCH( 
        TRUE(),
        Sales >= 0 &&  Sales <= q1 ,q1,
        Sales > q1 && Sales <= q2 ,q2,
        Sales > q2 && Sales  <= q3 ,q3,
        "Q4"
    )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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