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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
markdean
Regular Visitor

Help: Struggling with DAX to show Quartile Position in a table

Hi all - I am hoping someone can help me write a DAX measure to show 'Quartile Position' within a table. This is where I'm at...

Issue.PNG

This is the DAX I've written so far:

 

Quartile =

VAR SelectedUnit =

    CALCULATE ( 'MASTER_DATASET'[RANK])

VAR p25 =

    PERCENTILEX.INC (

        ALLSELECTED ( 'MASTER_DATASET'[Institution Name] ),

        CALCULATE ( [RANK] ),

        0.25

    )

VAR p50 =

    PERCENTILEX.INC (

        ALLSELECTED ( 'MASTER_DATASET'[Institution Name] ),

        CALCULATE ( [RANK] ),

        0.5

    )

VAR p75 =

    PERCENTILEX.INC (

        ALLSELECTED ( 'MASTER_DATASET'[Institution Name] ),

        CALCULATE ( [RANK] ),

        0.75

    )

RETURN

    SWITCH (

     ISFILTERED('MASTER_DATASET'[Institution Name]),

        SelectedUnit <= p25, "Q1",

        SelectedUnit > p25 && selectedunit <=p50, "Q2",

        selectedunit > p50 && SelectedUnit <= p75, "Q3",

        "Q4"

    )

 

It's the first time I've ever tried to show quartile position in a table so I'm struggling to work out how to resolve this, hence the plea for help! If anyone knows what tweaks I need to make to the above DAX to get this to work, then I'd really appreciate the input and advice. Thanks in advance - Mark 🙂 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @markdean,

I suppose they may relate to filter effect. If the filter effects applied on these records and only keep records that equal to current 'Institution Name' category, they should return wrong results due to calculation on the wrong ranges.

For this scenario, you can try to create a variable to stored filtered table records and ranks. Then you can use the max rank from the variable table to compare with current rank and use the result to assign group.

All the secrets of SUMMARIZE - SQLBI

Regards,

Xiaoxin Sheng

View solution in original post

5 REPLIES 5
markdean
Regular Visitor

Hi @Anonymous , thanks for the reply. Ive included two links below, 1 for some dummy data and 1 for a pbix file that should show the issue 👍 The original DAX works when I remove all filters. The problem seems to occur when filters are applied. There are two tables in the attached pbix that will show what I mean...Thanks again everyone 🙂 

Link 1: dummy data MarkDummyData.xlsx

Link 2: pbix Showing Quartiles Dummy Data.pbix

Anonymous
Not applicable

HI @markdean,

I suppose they may relate to filter effect. If the filter effects applied on these records and only keep records that equal to current 'Institution Name' category, they should return wrong results due to calculation on the wrong ranges.

For this scenario, you can try to create a variable to stored filtered table records and ranks. Then you can use the max rank from the variable table to compare with current rank and use the result to assign group.

All the secrets of SUMMARIZE - SQLBI

Regards,

Xiaoxin Sheng

bhanu_gautam
Super User
Super User

@markdean , Try using

DAX
Quartile =
VAR SelectedUnit =
CALCULATE ( 'MASTER_DATASET'[RANK] )
VAR p25 =
PERCENTILEX.INC (
ALLSELECTED ( 'MASTER_DATASET'[Institution Name] ),
CALCULATE ( [RANK] ),
0.25
)
VAR p50 =
PERCENTILEX.INC (
ALLSELECTED ( 'MASTER_DATASET'[Institution Name] ),
CALCULATE ( [RANK] ),
0.5
)
VAR p75 =
PERCENTILEX.INC (
ALLSELECTED ( 'MASTER_DATASET'[Institution Name] ),
CALCULATE ( [RANK] ),
0.75
)
RETURN
SWITCH (
TRUE(),
SelectedUnit <= p25, "Q1",
SelectedUnit > p25 && SelectedUnit <= p50, "Q2",
SelectedUnit > p50 && SelectedUnit <= p75, "Q3",
"Q4"
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam , many thanks for replying and for the suggestion. Sadly, it's still only producing a column of 24 Q1 values and is not returning any Q2, Q3 or Q4 values 😞

Anonymous
Not applicable

Hi @markdean ,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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