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

Breaking Up Customers into Quartiles based on # of Transactions

Trying to get a look at how many purchases our customers make. I have a data table that includes customer ID, and Transaction ID. How do I calculate something like the following using DAX.

 

Quartile 1 = 1 order

Quartile 2 = 1.5 orders

Quartile 3 = 2 orders

Quartile 4 = 4+ orders

 

I created a calculated column "Lifetime Orders" and tried this approach: http://community.powerbi.com/t5/Desktop/How-do-you-slice-data-into-quartiles-and-quintiles/m-p/15726...

 

but it is only returning values for quartile 1 and quartile 4, so something isn't right.

 

Quartile (Orders) # = 
var FirstQ = CALCULATE(PERCENTILE.INC('Order Information'[Lifetime Orders], .25), ALL('Order Information'[Lifetime Orders]))
var SecondQ = CALCULATE(PERCENTILE.INC('Order Information'[Lifetime Orders], .50), ALL('Order Information'[Lifetime Orders]))
var ThirdQ = CALCULATE(PERCENTILE.INC('Order Information'[Lifetime Orders], .75), ALL('Order Information'[Lifetime Orders]))
var ThisVal = MIN('Order Information'[Lifetime Orders])
return
		IF(ThisVal <= FirstQ, 1,
			IF(ThisVal > FirstQ && ThisVal <= SecondQ, 2, 
				IF(ThisVal > SecondQ && ThisVal <= ThirdQ, 3, 4)
		
		) 
) 

 

1 ACCEPTED SOLUTION

Hi @AAbell,

 

Please new a measure with below formula:

Quartile (Orders) # measure =
VAR FirstQ =
    PERCENTILEX.INC (
        ALL ( 'Order Information'[Lifetime Orders] ),
        'Order Information'[Lifetime Orders],
        .25
    )
VAR SecondQ =
    PERCENTILEX.INC (
        ALL ( 'Order Information'[Lifetime Orders] ),
        'Order Information'[Lifetime Orders],
        .50
    )
VAR ThirdQ =
    PERCENTILEX.INC (
        ALL ( 'Order Information'[Lifetime Orders] ),
        'Order Information'[Lifetime Orders],
        .75
    )
VAR ThisVal =
    SELECTEDVALUE ( 'Order Information'[Lifetime Orders] )
RETURN
    IF (
        ThisVal <= FirstQ,
        1,
        IF (
            ThisVal > FirstQ
                && ThisVal <= SecondQ,
            2,
            IF ( ThisVal > SecondQ && ThisVal <= ThirdQ, 3, 4 )
        )
    )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Employee
Employee

Hi @AAbell,

 

The DAX formula looks correct. Please share your sample data and show us your desired result so that I can check for you.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Here is a sample data set. 

Customer IDLifetime Orders
1234561
1234581
1234601
1234622
1234641
1234663
1234681
1234701
1234721
1234741
1234762
1234781
1234803
1234821
1234841
1234861
1234881
12349010
1234921
1234941
1234962
1234981
1235001
1235021
1235041
1235061

 

I'm expecting something like this, but it's returning only 1's and 4's 

Customer IDLifetime OrdersQuartile
12345611
12345811
12346011
12346222
12346411
12346633
12346811
12347011
12347211
12347411
12347622
12347811
12348033
12348211
12348411
12348611
12348811
123490104
12349211
12349411
12349622
12349811
12350011
12350211
12350411
12350611

 

I'm wondering if it is because I have such a huge dataset and around 80% of the values are 1, making the mean 1 and forcing things into either quartile 1 or 4.

 

If so, is there a way to chunk or bucket these in power BI? Is 1 = bucket 1, is between 1 and 2 = bucket 2, is between 2 and 3 = bucket 3, is 4 or more = bucket 4?

Hi @AAbell,

 

Please new a measure with below formula:

Quartile (Orders) # measure =
VAR FirstQ =
    PERCENTILEX.INC (
        ALL ( 'Order Information'[Lifetime Orders] ),
        'Order Information'[Lifetime Orders],
        .25
    )
VAR SecondQ =
    PERCENTILEX.INC (
        ALL ( 'Order Information'[Lifetime Orders] ),
        'Order Information'[Lifetime Orders],
        .50
    )
VAR ThirdQ =
    PERCENTILEX.INC (
        ALL ( 'Order Information'[Lifetime Orders] ),
        'Order Information'[Lifetime Orders],
        .75
    )
VAR ThisVal =
    SELECTEDVALUE ( 'Order Information'[Lifetime Orders] )
RETURN
    IF (
        ThisVal <= FirstQ,
        1,
        IF (
            ThisVal > FirstQ
                && ThisVal <= SecondQ,
            2,
            IF ( ThisVal > SecondQ && ThisVal <= ThirdQ, 3, 4 )
        )
    )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Yuliana! This worked - but I found out the problem was that I had so many orders of only 1, that the median was 1 and therefore the 1st, 2nd and 3rd quartiles were all 1 as well.

 

I appreciate your assistance!

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.