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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
jjmartinso
Frequent Visitor

Quartile calculation with multiple conditions

Hello All, 

I have searched for the solution on this, and I have tried multiple things. However, I have not been successful.  I am trying to calculate the quartile for Hours and Quantity in the below table.  The first five columns of the below snapshot is coming from the Asset table, Hours is coming from the Activity table, and Quantity is coming from the Delivery table.  Additionally, the visual is filtered by date (last 3 calendar months).

 

Condition: The assets should be evaluated on the Line of Bus and Category.  For example, for the first row, I am trying to see what quartile the 171 hours falls into based on the Operations Line of Bus and the Pickup Category.  For the last line, I am trying to see what quartile the 1,539 hours falls into and what quartile the quantity of 3,901,873 falls into based on Fuel Line of Bus and the Tractor Category 

 

My Power BI report currently contains columns A through I.  Columns J - K are not included and rows after 14 are not included.  The Hours Quart and Quant Quart, column H & I, is where I need assistance.

 

1ABCDEFGIJK
2Unit NumberRegionLine of BusinessUnit ClassCategorySum of HoursSum of QuantityHours QuartQuant Quart Helper
3MTR2023802CentralFuelPower UnitTractor1317.8122760114 FuelTractor
4MTR2023810CentralFuelPower UnitTractor1789.83144413.9944 FuelTractor
5MTR2023806CentralFuelPower UnitTractor1691.5814354834 FuelTractor
6MTR2023803CentralOperationsPower UnitTruck1347.4714060514 OperationsTruck
7MTR2023808CentralOperationsPower UnitTruck2179.6112113011 OperationsTruck
9MTR2023807CentralFuelPower UnitTractor584.3510039914 FuelTractor
10MTR2084703CentralFuelPower UnitTractor765.89790214 FuelTractor
11MTR2084704CentralFuelPower UnitTractor1627.949327224 FuelTractor
12MTR2023812CentralFuelPower UnitTractor1711.716569844 FuelTractor
13MTR2023809CentralFuelPower UnitTractor13515132024 FuelTractor
14MTR2023813CentralFuelPower UnitTractor1639.551481234 FuelTractor
15           
16  Unique1234    
17  FuelTractor1317.811627.941691.581789.83    
18  OperationsTruck125998.75130868135736.25140605    

 

On the above sample table from Excel, I used a helper column (cell K3 formula =D3&F3). 

The table below the data, starting on row 16, is the quartile table that I used for my Hours Quart and Quant Quart formulas.  This is only to help calculate the formulas in columns H & I

D17 formula is: QUARTILE.INC(IF($L$3:$L$13=$D16,$G$3:$G$13),E$15)

The formula used for Column H is:

IF(G3<=INDEX($E$16:$H$17,MATCH($L3,$D$16:$D$17,0),1),1,IF(G3<=INDEX($E$16:$H$17,MATCH($L3,$D$16:$D$17,0),2),2,IF(G3<=INDEX($E$16:$H$17,MATCH($L3,$D$16:$D$17,0),3),3,4)))

 

One additional aspect, the table in Power BI also includes filters for Region, Line of Business, and Category, shown in the below.  I am not sure if this would need to be incorporated in a dax formula.

jjmartinso_0-1681937822111.png

 

I would greatly appreciate any guidance or assistance to incorporate this logic in Power BI.  Thanks!

 

7 REPLIES 7
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

@lbendlin , I have modified the original post to include an Excel example.  I hope that provides enough detail.  If not, let me know.

It would be something like this

Hours Quartile = 
SWITCH(TRUE(),
sum('Table'[Sum of Hours])<calculate(PERCENTILE.INC('Table'[Sum of Hours],0.25),ALLSELECTED('Table')),1,
sum('Table'[Sum of Hours])<calculate(PERCENTILE.INC('Table'[Sum of Hours],0.5),ALLSELECTED('Table')),2,
sum('Table'[Sum of Hours])<calculate(PERCENTILE.INC('Table'[Sum of Hours],0.75),ALLSELECTED('Table')),3,
4)

lbendlin_0-1682281325425.png

 

Thanks Ibendlin.  I am still having an issue with the percentile pieces: 

calculate(PERCENTILE.INC('Table'[Sum of Hours],0.25),ALLSELECTED('Table'))

The table that I am referencing has many line items that add up to the total 'sum of hours'.  For instance, the max in the Hours column is 375.  The line above appears to be looking at those individual line items to calculate the quartile vs the summed amount per a 'Unit Number'.

Please provide sanitized sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

I am trying to produce a summarized table similar to the below.  The hours are the sum of the hours from the data table.  The Quartile is based on the hours for the line of business and category. 

 

H

I

J

K

L

M

 

Truck

Region

Line of Business

Category

Hours

Quartile

4

2

Central

Fuel

Tractor

1,317.81

1

5

3

Central

Operations

Truck

1,347.47

1

6

4

Central

Fuel

Tractor

1,627.94

2

7

5

Central

Fuel

Tractor

765.80

1

8

6

Central

Fuel

Tractor

1,691.58

3

9

7

Central

Fuel

Tractor

584.35

1

10

8

Central

Operations

Truck

2,179.61

4

11

9

Central

Fuel

Tractor

1,351.00

2

12

10

Central

Fuel

Tractor

144,413.99

4

13

12

Central

Fuel

Tractor

1,711.71

4

14

13

Central

Fuel

Tractor

1,639.55

3

The formula in M4 is: IF(L4<=INDEX($T$5:$W$6,MATCH(Q4,$S$5:$S$6,0),1),1,IF(L4<=INDEX($T$5:$W$6,MATCH(Q4,$S$5:$S$6,0),2),2,IF(L4<=INDEX($T$5:$W$6,MATCH(Q4,$S$5:$S$6,0),3),3,4)))

 

Here is a sample dataset that is used to populate the Summary table, above.

 

B

D

E

F

 

Truck

Region

Line of Business

Category

Hours

4

2

Central

Fuel

Tractor

500.50

5

10

Central

Fuel

Tractor

68,005.00

6

6

Central

Fuel

Tractor

0.00

7

3

Central

Operations

Truck

852.60

8

8

Central

Operations

Truck

765.00

9

7

Central

Fuel

Tractor

135.60

10

5

Central

Fuel

Tractor

653.40

11

4

Central

Fuel

Tractor

398.63

12

12

Central

Fuel

Tractor

403.80

13

9

Central

Fuel

Tractor

345.00

14

13

Central

Fuel

Tractor

800.60

15

2

Central

Fuel

Tractor

653.00

16

10

Central

Fuel

Tractor

29,432.00

17

6

Central

Fuel

Tractor

698.00

18

3

Central

Operations

Truck

135.70

19

8

Central

Operations

Truck

657.00

20

7

Central

Fuel

Tractor

263.10

21

5

Central

Fuel

Tractor

86.90

22

4

Central

Fuel

Tractor

635.14

23

12

Central

Fuel

Tractor

742.50

24

9

Central

Fuel

Tractor

654.10

25

13

Central

Fuel

Tractor

498.60

26

2

Central

Fuel

Tractor

164.31

27

10

Central

Fuel

Tractor

46,976.99

28

6

Central

Fuel

Tractor

993.58

29

3

Central

Operations

Truck

359.17

30

8

Central

Operations

Truck

757.61

31

7

Central

Fuel

Tractor

185.65

32

5

Central

Fuel

Tractor

25.50

33

4

Central

Fuel

Tractor

594.17

34

12

Central

Fuel

Tractor

565.41

35

9

Central

Fuel

Tractor

351.90

36

13

Central

Fuel

Tractor

340.35

 

To get the summarized table in Excel, I used a Helper column (concatenate Line of Business & Category). 

 

Q

 

Helper

4

FuelTractor

5

OperationsTruck

6

FuelTractor

7

FuelTractor

8

FuelTractor

9

FuelTractor

10

OperationsTruck

11

FuelTractor

12

FuelTractor

13

FuelTractor

14

FuelTractor

The formula in Q4 is: J4&K4

Part 2:

To calculate the quartile in Excel, I produced a reference table:

 S T  U  V  W 
      
4Quartile 1          1.00          2.00          3.00              4.00
5FuelTractor  1,317.81  1,627.94  1,691.58  144,413.99
6OperationsTruck  1,555.51  1,763.54  1,971.58      2,179.61

The formula in T5 is: QUARTILE.INC(IF($Q$4:$Q$14=$S5,$L$4:$L$14),T$4)

 

Based on this sample data, I believe the dax formula is generating a Quartile table like this:

 S T  U  V  W 
9Quartile2          1.00          2.00          3.00              4.00
10      340.35     565.41     742.50    68,005.00


The formula in T10 is: QUARTILE.INC($F$4:$F$36,T$9)
And this is producing the Quartiles shown in Quartile 2:

 HIJKLM O
 TruckRegionLine of BusinessCategoryHoursQuartile Quartile2
42CentralFuelTractor1,317.811 4
53CentralOperationsTruck1,347.471 4
64CentralFuelTractor1,627.942 4
75CentralFuelTractor765.801 4
86CentralFuelTractor1,691.583 4
97CentralFuelTractor584.351 3
108CentralOperationsTruck2,179.614 4
119CentralFuelTractor1,351.002 4
1210CentralFuelTractor144,413.994 4
1312CentralFuelTractor1,711.714 4
1413CentralFuelTractor1,639.553 4


The difference in the quartile calcs is using the summed hours in the summary table vs the individual line items in the dataset.

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.