Percentile of n most recent values

Fitzy22

New Member
Joined
Jan 19, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi,

Please see simplified minisheet of my data below.

I would like to calculate the 80th percentile of the most recent (i.e. dates in Column A) 24 values (i.e. values in Column C) for each site (i.e. x and y in Column B). Where there is no value for a particular date it means there is no value recorded and therefore needs to be ignored and doesn't from part of the percentile calculation. So only the 24 most recent "values" should be used.

I hope this adequately explains my requirements, but if there are any questions please ask.

Thanks in advance...

Percentile_calculation.xlsx
ABC
1DateSiteValue
225/12/2006x
321/12/2007x1
421/12/2007x2
518/11/2008x
618/11/2008x
728/11/2008y
828/11/2008y1
928/11/2008y2
1028/11/2008y
1128/11/2008y
1228/11/2008y
1328/11/2008x
1412/01/2009x
1512/01/2009x1
1612/01/2009y1
1712/01/2009y1
1812/01/2009y
1912/01/2009x
2012/01/2009y
2112/01/2009x
2212/01/2009y
2312/01/2009x
2417/01/2009x
2517/01/2009x2
2617/01/2009y
2717/01/2009y
2817/01/2009y
2917/01/2009x
301/01/2010x
311/01/2010x10
3215/02/2010x
3315/02/2010x
3415/02/2010y3
3518/02/2010x
3618/02/2010x
3718/02/2010x
3818/02/2010x
3918/02/2010x
4017/01/2011x4
419/03/2011x8
429/05/2011x3
437/03/2012x1
4426/02/2013x2
457/03/2013x1
461/03/2014x2.1
474/12/2014x3.4
484/12/2014y2.4
497/12/2014y1.2
507/12/2014y1.5
5114/12/2014x2
5214/12/2014x1.8
5329/12/2014x2.7
5416/01/2015x2.3
557/11/2015x
566/02/2016x2.3
5713/05/2016x3.2
5813/05/2016x2.5
5927/06/2016y1.1
6024/09/2016y1.4
6124/09/2016y1
6224/02/2017x1.1
633/03/2018x4.1
645/03/2018x9.1
655/03/2018x9
665/03/2018x7.8
676/03/2018x2.8
688/03/2018x5.3
698/03/2018x5.4
708/03/2018x3.3
719/03/2018x7.8
7224/02/2019x1.6
7324/02/2019x3.2
7431/03/2019y1.6
7531/03/2019y3.7
7625/01/2020y1.9
7727/01/2020x6.7
7827/01/2020x2.7
7927/01/2020x1.3
805/02/2020x4.6
818/03/2020y4.4
828/03/2020x0.8
8326/09/2020x1.6
8426/09/2020x2.2
8525/12/2020x1.7
8610/03/2021x14
8723/03/2021x1.4
8824/06/2021x2.4
8929/10/2021x4.2
9021/01/2022x7.5
9124/01/2022x12
9226/01/2022x2.2
Sheet1
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Map1
ABCDEFGHI
1DateSiteValuedate'count62
225/12/2006x large 24 4316768<<<<< on row
321/12/2007x139437large 24 with row incl43167,0169<<<<< on row
421/12/2007x239437
518/11/2008x 
618/11/2008x your answeer5,92
728/11/2008y 
828/11/2008y139780
928/11/2008y239780
1028/11/2008y 
1128/11/2008y 
1228/11/2008y 
1328/11/2008x 
1412/01/2009x 
1512/01/2009x139825
1612/01/2009y139825
1712/01/2009y139825
1812/01/2009y 
1912/01/2009x 
2012/01/2009y 
2112/01/2009x 
2212/01/2009y 
2312/01/2009x 
2417/01/2009x 
2517/01/2009x239830
2617/01/2009y 
2717/01/2009y 
2817/01/2009y 
2917/01/2009x 
301/01/2010x 
311/01/2010x1040179
3215/02/2010x 
3315/02/2010x 
3415/02/2010y340224
3518/02/2010x 
3618/02/2010x 
3718/02/2010x 
3818/02/2010x 
3918/02/2010x 
4017/01/2011x440560
419/03/2011x840611
429/05/2011x340672
437/03/2012x140975
4426/02/2013x241331
457/03/2013x141340
461/03/2014x2,141699
474/12/2014x3,441977
484/12/2014y2,441977
497/12/2014y1,241980
507/12/2014y1,541980,01
5114/12/2014x241987,01
5214/12/2014x1,841987,01
5329/12/2014x2,742002,01
5416/01/2015x2,342020,01
557/11/2015x 
566/02/2016x2,342406,01
5713/05/2016x3,242503,01
5813/05/2016x2,542503,01
5927/06/2016y1,142548,01
6024/09/2016y1,442637,01
6124/09/2016y142637,01
6224/02/2017x1,142790,01
633/03/2018x4,143162,01
645/03/2018x9,143164,01
655/03/2018x943164,01
665/03/2018x7,843164,01
676/03/2018x2,843165,01
688/03/2018x5,343167,01
698/03/2018x5,443167,01
708/03/2018x3,343167,01
719/03/2018x7,843168,01
7224/02/2019x1,643520,01
7324/02/2019x3,243520,01
7431/03/2019y1,643555,01
7531/03/2019y3,743555,01
7625/01/2020y1,943855,01
7727/01/2020x6,743857,01
7827/01/2020x2,743857,01
7927/01/2020x1,343857,01
805/02/2020x4,643866,01
818/03/2020y4,443898,01
828/03/2020x0,843898,01
8326/09/2020x1,644100,01
8426/09/2020x2,244100,01
8525/12/2020x1,744190,01
8610/03/2021x1444265,01
8723/03/2021x1,444278,01
8824/06/2021x2,444371,01
8929/10/2021x4,244498,01
9021/01/2022x7,544582,01
9124/01/2022x1244585,01
9226/01/2022x2,244587,01
Blad1
Cell Formulas
RangeFormula
F1F1=COUNT(C:C)
F2F2=LARGE(A:A,24)
G2G2=MATCH(F2,A:A,0)
F3F3=LARGE(D2:D92,24)
G3G3=MATCH(F3,D:D,0)
F6F6=AGGREGATE(16,6,$C$2:$C$92/(($D$2:$D$92>=F3)*($C$2:$C$92<>"")),0.8)
D2:D92D2=IF(C2<>"",A2+ROW()/10000,"")
 
Upvote 0
EDIT : my previous answer was wrong, but i can't correct or remove it anymore :cry:
as you have 365, it can be done with a LET-formula, but that's for the LET-nerds


Map1
ABCDEFGHI
1DateSiteValuedate'
225/12/2006x 
321/12/2007x139437
421/12/2007x239437
518/11/2008x 
618/11/2008x 
728/11/2008y 
828/11/2008y139780100000
928/11/2008y239780countlarge 24perc
1028/11/2008y x4743164,00077,8
1128/11/2008y y15not enoughnot enough
1228/11/2008y 
1328/11/2008x 
1412/01/2009x 
1512/01/2009x139825
1612/01/2009y139825
1712/01/2009y139825
1812/01/2009y 
1912/01/2009x 
2012/01/2009y 
2112/01/2009x 
2212/01/2009y 
2312/01/2009x 
2417/01/2009x 
2517/01/2009x239830
2617/01/2009y 
2717/01/2009y 
2817/01/2009y 
2917/01/2009x 
301/01/2010x 
311/01/2010x1040179
3215/02/2010x 
3315/02/2010x 
3415/02/2010y340224
3518/02/2010x 
3618/02/2010x 
3718/02/2010x 
3818/02/2010x 
3918/02/2010x 
4017/01/2011x440560
419/03/2011x840611
429/05/2011x340672
437/03/2012x140975
4426/02/2013x241331
457/03/2013x141340
461/03/2014x2,141699
474/12/2014x3,441977
484/12/2014y2,441977
497/12/2014y1,241980
507/12/2014y1,541980,01
5114/12/2014x241987,01
5214/12/2014x1,841987,01
5329/12/2014x2,742002,01
5416/01/2015x2,342020,01
557/11/2015x 
566/02/2016x2,342406,01
5713/05/2016x3,242503,01
5813/05/2016x2,542503,01
5927/06/2016y1,142548,01
6024/09/2016y1,442637,01
6124/09/2016y142637,01
6224/02/2017x1,142790,01
633/03/2018x4,143162,01
645/03/2018x9,143164,01
655/03/2018x943164,01
665/03/2018x7,843164,01
676/03/2018x2,843165,01
688/03/2018x5,343167,01
698/03/2018x5,443167,01
708/03/2018x3,343167,01
719/03/2018x7,843168,01
7224/02/2019x1,643520,01
7324/02/2019x3,243520,01
7431/03/2019y1,643555,01
7531/03/2019y3,743555,01
7625/01/2020y1,943855,01
7727/01/2020x6,743857,01
7827/01/2020x2,743857,01
7927/01/2020x1,343857,01
805/02/2020x4,643866,01
818/03/2020y4,443898,01
828/03/2020x0,843898,01
8326/09/2020x1,644100,01
8426/09/2020x2,244100,01
8525/12/2020x1,744190,01
8610/03/2021x1444265,01
8723/03/2021x1,444278,01
8824/06/2021x2,444371,01
8929/10/2021x4,244498,01
9021/01/2022x7,544582,01
9124/01/2022x1244585,01
9226/01/2022x2,244587,01
Blad1
Cell Formulas
RangeFormula
G10:G11G10=SUMPRODUCT(($B$2:$B$92=F10)*($C$2:$C$92<>""))
H10:H11H10=IF(G10>=24,AGGREGATE(14,6,($A$2:$A$92+ROW($A$2:$A$92)/$G$8)/(($B$2:$B$92=F10)*($C$2:$C$92<>"")),24),"not enough")
I10:I11I10=IF(ISNUMBER(H10),AGGREGATE(16,6,$C$2:$C$92/(($D$2:$D$92>=$H10)*($C$2:$C$92<>"")*($B$2:$B$92=$F10)),0.8),"not enough")
D2:D92D2=IF(C2<>"",A2+ROW()/10000,"")
 
Upvote 0
Here is another idea using some other Excel 365 functions. Note: in some cases, what should happen if the number of values is smaller than 24? That is the case for Site "y", so I included a provision to use the minimum number of values between 24 and the actual number. The count of the values is shown in E1:F1. The 80th percentile (inclusive) for each site is in E3:F3.
Book3
ABCDEFG
1DateSiteValue4715<--Count
225/12/2006xxy
321/12/2007x17.622.52<---80th percentile
421/12/2007x2
518/11/2008x
618/11/2008x
728/11/2008y
828/11/2008y1
928/11/2008y2
1028/11/2008y
1128/11/2008y
1228/11/2008y
1328/11/2008x
1412/01/2009x
1512/01/2009x1
1612/01/2009y1
1712/01/2009y1
1812/01/2009y
1912/01/2009x
2012/01/2009y
2112/01/2009x
2212/01/2009y
2312/01/2009x
2417/01/2009x
2517/01/2009x2
2617/01/2009y
2717/01/2009y
2817/01/2009y
2917/01/2009x
3001/01/2010x
3101/01/2010x10
3215/02/2010x
3315/02/2010x
3415/02/2010y3
3518/02/2010x
3618/02/2010x
3718/02/2010x
3818/02/2010x
3918/02/2010x
4017/01/2011x4
4109/03/2011x8
4209/05/2011x3
4307/03/2012x1
4426/02/2013x2
4507/03/2013x1
4601/03/2014x2.1
4704/12/2014x3.4
4804/12/2014y2.4
4907/12/2014y1.2
5007/12/2014y1.5
5114/12/2014x2
5214/12/2014x1.8
5329/12/2014x2.7
5416/01/2015x2.3
5507/11/2015x
5606/02/2016x2.3
5713/05/2016x3.2
5813/05/2016x2.5
5927/06/2016y1.1
6024/09/2016y1.4
6124/09/2016y1
6224/02/2017x1.1
6303/03/2018x4.1
6405/03/2018x9.1
6505/03/2018x9
6605/03/2018x7.8
6706/03/2018x2.8
6808/03/2018x5.3
6908/03/2018x5.4
7008/03/2018x3.3
7109/03/2018x7.8
7224/02/2019x1.6
7324/02/2019x3.2
7431/03/2019y1.6
7531/03/2019y3.7
7625/01/2020y1.9
7727/01/2020x6.7
7827/01/2020x2.7
7927/01/2020x1.3
8005/02/2020x4.6
8108/03/2020y4.4
8208/03/2020x0.8
8326/09/2020x1.6
8426/09/2020x2.2
8525/12/2020x1.7
8610/03/2021x14
8723/03/2021x1.4
8824/06/2021x2.4
8929/10/2021x4.2
9021/01/2022x7.5
9124/01/2022x12
9226/01/2022x2.2
Sheet1
Cell Formulas
RangeFormula
E1:F1E1=SUM(($B$2:$B$92=E$2)*($C$2:$C$92<>""))
E3:F3E3=PERCENTILE.INC(INDEX(SORT(FILTER(FILTER($A$2:$C$92,($B$2:$B$92=E$2)*($C$2:$C$92<>"")),{1,0,1}),1,-1),SEQUENCE(MIN(24,SUM(($B$2:$B$92=E$2)*($C$2:$C$92<>"")))),2),0.8)
 
Upvote 0
EDIT : my previous answer was wrong, but i can't correct or remove it anymore :cry:
as you have 365, it can be done with a LET-formula, but that's for the LET-nerds


Map1
ABCDEFGHI
1DateSiteValuedate'
225/12/2006x 
321/12/2007x139437
421/12/2007x239437
518/11/2008x 
618/11/2008x 
728/11/2008y 
828/11/2008y139780100000
928/11/2008y239780countlarge 24perc
1028/11/2008y x4743164,00077,8
1128/11/2008y y15not enoughnot enough
1228/11/2008y 
1328/11/2008x 
1412/01/2009x 
1512/01/2009x139825
1612/01/2009y139825
1712/01/2009y139825
1812/01/2009y 
1912/01/2009x 
2012/01/2009y 
2112/01/2009x 
2212/01/2009y 
2312/01/2009x 
2417/01/2009x 
2517/01/2009x239830
2617/01/2009y 
2717/01/2009y 
2817/01/2009y 
2917/01/2009x 
301/01/2010x 
311/01/2010x1040179
3215/02/2010x 
3315/02/2010x 
3415/02/2010y340224
3518/02/2010x 
3618/02/2010x 
3718/02/2010x 
3818/02/2010x 
3918/02/2010x 
4017/01/2011x440560
419/03/2011x840611
429/05/2011x340672
437/03/2012x140975
4426/02/2013x241331
457/03/2013x141340
461/03/2014x2,141699
474/12/2014x3,441977
484/12/2014y2,441977
497/12/2014y1,241980
507/12/2014y1,541980,01
5114/12/2014x241987,01
5214/12/2014x1,841987,01
5329/12/2014x2,742002,01
5416/01/2015x2,342020,01
557/11/2015x 
566/02/2016x2,342406,01
5713/05/2016x3,242503,01
5813/05/2016x2,542503,01
5927/06/2016y1,142548,01
6024/09/2016y1,442637,01
6124/09/2016y142637,01
6224/02/2017x1,142790,01
633/03/2018x4,143162,01
645/03/2018x9,143164,01
655/03/2018x943164,01
665/03/2018x7,843164,01
676/03/2018x2,843165,01
688/03/2018x5,343167,01
698/03/2018x5,443167,01
708/03/2018x3,343167,01
719/03/2018x7,843168,01
7224/02/2019x1,643520,01
7324/02/2019x3,243520,01
7431/03/2019y1,643555,01
7531/03/2019y3,743555,01
7625/01/2020y1,943855,01
7727/01/2020x6,743857,01
7827/01/2020x2,743857,01
7927/01/2020x1,343857,01
805/02/2020x4,643866,01
818/03/2020y4,443898,01
828/03/2020x0,843898,01
8326/09/2020x1,644100,01
8426/09/2020x2,244100,01
8525/12/2020x1,744190,01
8610/03/2021x1444265,01
8723/03/2021x1,444278,01
8824/06/2021x2,444371,01
8929/10/2021x4,244498,01
9021/01/2022x7,544582,01
9124/01/2022x1244585,01
9226/01/2022x2,244587,01
Blad1
Cell Formulas
RangeFormula
G10:G11G10=SUMPRODUCT(($B$2:$B$92=F10)*($C$2:$C$92<>""))
H10:H11H10=IF(G10>=24,AGGREGATE(14,6,($A$2:$A$92+ROW($A$2:$A$92)/$G$8)/(($B$2:$B$92=F10)*($C$2:$C$92<>"")),24),"not enough")
I10:I11I10=IF(ISNUMBER(H10),AGGREGATE(16,6,$C$2:$C$92/(($D$2:$D$92>=$H10)*($C$2:$C$92<>"")*($B$2:$B$92=$F10)),0.8),"not enough")
D2:D92D2=IF(C2<>"",A2+ROW()/10000,"")

A huge thanks to BSALV and KRice!!

It may well have taken me days to come up with either of those solutions ;).

KRice, the formula you prepared is perfect for my spreadsheet as I don't have space for helper cells for the calculation. In fact, I only have one cell for each site. Will the formula in E3 work by itself without the need to reference E1? I do have a column containing each site which will be the equivalent to E$2.

Once again, so much appreciation for your help with this and love your excel skills.

Cheers, Fitzy.
 
Upvote 0
A huge thanks to BSALV and KRice!!

It may well have taken me days to come up with either of those solutions ;).

KRice, the formula you prepared is perfect for my spreadsheet as I don't have space for helper cells for the calculation. In fact, I only have one cell for each site. Will the formula in E3 work by itself without the need to reference E1? I do have a column containing each site which will be the equivalent to E$2.

Once again, so much appreciation for your help with this and love your excel skills.

Cheers, Fitzy.
 
Upvote 0
Here is another idea using some other Excel 365 functions. Note: in some cases, what should happen if the number of values is smaller than 24? That is the case for Site "y", so I included a provision to use the minimum number of values between 24 and the actual number. The count of the values is shown in E1:F1. The 80th percentile (inclusive) for each site is in E3:F3.
Book3
ABCDEFG
1DateSiteValue4715<--Count
225/12/2006xxy
321/12/2007x17.622.52<---80th percentile
421/12/2007x2
518/11/2008x
618/11/2008x
728/11/2008y
828/11/2008y1
928/11/2008y2
1028/11/2008y
1128/11/2008y
1228/11/2008y
1328/11/2008x
1412/01/2009x
1512/01/2009x1
1612/01/2009y1
1712/01/2009y1
1812/01/2009y
1912/01/2009x
2012/01/2009y
2112/01/2009x
2212/01/2009y
2312/01/2009x
2417/01/2009x
2517/01/2009x2
2617/01/2009y
2717/01/2009y
2817/01/2009y
2917/01/2009x
3001/01/2010x
3101/01/2010x10
3215/02/2010x
3315/02/2010x
3415/02/2010y3
3518/02/2010x
3618/02/2010x
3718/02/2010x
3818/02/2010x
3918/02/2010x
4017/01/2011x4
4109/03/2011x8
4209/05/2011x3
4307/03/2012x1
4426/02/2013x2
4507/03/2013x1
4601/03/2014x2.1
4704/12/2014x3.4
4804/12/2014y2.4
4907/12/2014y1.2
5007/12/2014y1.5
5114/12/2014x2
5214/12/2014x1.8
5329/12/2014x2.7
5416/01/2015x2.3
5507/11/2015x
5606/02/2016x2.3
5713/05/2016x3.2
5813/05/2016x2.5
5927/06/2016y1.1
6024/09/2016y1.4
6124/09/2016y1
6224/02/2017x1.1
6303/03/2018x4.1
6405/03/2018x9.1
6505/03/2018x9
6605/03/2018x7.8
6706/03/2018x2.8
6808/03/2018x5.3
6908/03/2018x5.4
7008/03/2018x3.3
7109/03/2018x7.8
7224/02/2019x1.6
7324/02/2019x3.2
7431/03/2019y1.6
7531/03/2019y3.7
7625/01/2020y1.9
7727/01/2020x6.7
7827/01/2020x2.7
7927/01/2020x1.3
8005/02/2020x4.6
8108/03/2020y4.4
8208/03/2020x0.8
8326/09/2020x1.6
8426/09/2020x2.2
8525/12/2020x1.7
8610/03/2021x14
8723/03/2021x1.4
8824/06/2021x2.4
8929/10/2021x4.2
9021/01/2022x7.5
9124/01/2022x12
9226/01/2022x2.2
Sheet1
Cell Formulas
RangeFormula
E1:F1E1=SUM(($B$2:$B$92=E$2)*($C$2:$C$92<>""))
E3:F3E3=PERCENTILE.INC(INDEX(SORT(FILTER(FILTER($A$2:$C$92,($B$2:$B$92=E$2)*($C$2:$C$92<>"")),{1,0,1}),1,-1),SEQUENCE(MIN(24,SUM(($B$2:$B$92=E$2)*($C$2:$C$92<>"")))),2),0.8)

Hi again KRice,

I have attempted to replicate this formula in my spreadsheet and I get a #VALUE! error. I think this is because the values column is separated from the date and site column by a number of intervening columns. Do you know if there are any additions or modifications to the formula that might account for that. In addition to the sites, I also have numerous values columns of different types that I need to calculate the percentiles for.

Regards, Fitzy.
 
Upvote 0
Fitzy, yes...some adjustments are needed. First, the E1:F1 formula isn't necessary, but it serves to indicate how many values satisfy the match criteria (whether site x or y and value is non-blank). If the number reported back is 24 or greater, then your original expectation is met (the most recent 24 values were used). If the number reported back is less than 24, then all of them are used...and in that case the number used is what appears in E1:F1 for that column. If you don't need to see this bit of information, then no, the E1:F1 formula is not needed, and the main formula does not reference E1 or F1.

Regarding the aim to adapt this formula, it should be straight forward, but the table structure does matter. In the formula:
Excel Formula:
=PERCENTILE.INC(INDEX(SORT(FILTER(FILTER($A$2:$C$92,($B$2:$B$92=E$2)*($C$2:$C$92<>"")),{1,0,1}),1,-1),SEQUENCE(MIN(24,SUM(($B$2:$B$92=E$2)*($C$2:$C$92<>"")))),2),0.8)
...the innermost FILTER needs to be adjusted to cover the entire range of data so that "Date" and "Value" are in the range. In the current example, Date is in column A and Value in column C, so
Excel Formula:
FILTER($A$2:$C$92,($B$2:$B$92=E$2)*($C$2:$C$92<>""))
$A$2:$C$92 captures both of them and the row range 2:92 covers all of the data that is needed. The filtering criteria may need to be adjusted, where here we have the "Site is x or y" criteria represented by ($B$2:$B$92=E$2). Adjust that range reference as needed, and determine whether you want to refer to the cell containing "x" (as in E$2 here) or simply replace that with "x" (surrounded by quotes since it is a text value)...this would be considered as hardwiring "x" into the formula, and if you do that, then another formula would look just like this one except a "y" would be hardwired into it. Then the non-blank value criteria must be multiplied by x or y criteria just described, so ($C$2:$C$92<>"") needs to refer to the data in the Value column. The rows represented by all of these must be the same (notice all are 2:92...adjust that to fit your data). That completes edits to the inner FILTER which I'll refer to a "filter inner" below.

The outer FILTER then needs to be adjusted. Currently it looks like this:
Excel Formula:
FILTER(filter inner,{1,0,1})
...that array of 1's and 0's is used to consolidate the array and essentially turn on (1) or off (0) a column. Since I want Date and Value in column A and C, the array is {1,0,1}. If you have a wider array, at this point, say Date and Value are in A and E, the turn on/off column filter array would be {1,0,0,0,1}. Make this adjustment and you should have at this point a two-column array of filtered data consisting of Date and Value produced by what I'll refer to as the "filter outer" below.

Then the data need to be sorted by date, in descending order, so
Excel Formula:
SORT(filter outer,1,-1)
...accomplishes that, where the "1" refers to the column where Date is found in the "filter outer" array. Since Date appears in "filter outer's" 1st column, I've used a 1. The "-1" means to sort in descending order, so this places the most recent dates (i.e., largest dates) at the top.

Then we need to cut off this list so that no more than 24 values are considered, so this filtered and sorted array is fed into the INDEX function:
Excel Formula:
INDEX(filtered and sorted array, SEQUENCE(MIN(24,SUM(($B$2:$B$92=E$2)*($C$2:$C$92<>"")))), 2)
Here is where an array of values for the rows to use is constructed with the SEQUENCE function. If you knew that you would always have at least 24 data points that met your criteria, the function would simply be SEQUENCE(24) which constructs an array {1;2;3;...24} to tell the INDEX function to return only those row indexes in the filtered and sorted array. But it appears that in some cases you may have fewer values, so a provision is made to account for that:
Excel Formula:
MIN(24, SUM(  ($B$2:$B$92=E$2) * ($C$2:$C$92<>"") ) )
You will see your two original filtering criteria...they should be the same as what you used before. By multiplying those criteria together and then taking the SUM, we will get the count of the number of data values satisfying the criteria . We then compare that sum to 24 and use whichever is smaller as the input to the SEQUENCE function to create the array of row indexes to use in the INDEX function. Since the "filtered and sorted array" from the previous step includes the Values in the 2nd column, the INDEX function must be told to extract data from that column...that is what the "2" does in the INDEX function. This produces a single column of values that represent your filtering criteria, and they number 24 (if available) or some smaller count. This array of values is then passed to the PERCENTILE.INC function, and no changes should be needed with it.

Please post back with some details if you have any questions.
 
Upvote 0
As @BSALV mentioned, the LET function can be used. Here it is used to reduce some redundancy and slightly shorten the formula. Within the LET function, we define a new variable named fcrit and assign to it your filter criteria array that appears twice in the formula I originally presented. Now it is defined once and then referred to twice with its shorter name.
Excel Formula:
=LET(fcrit,($B$2:$B$92=E$2)*($C$2:$C$92<>""), PERCENTILE.INC(INDEX(SORT(FILTER(FILTER($A$2:$C$92,fcrit),{1,0,1}),1,-1),SEQUENCE(MIN(24,SUM(fcrit))),2),0.8))
 
Upvote 0
Thanks for the explanation KRice, it clarifies a lot regarding the workings of the formula and the changes have resulted in a working formula!! In excel, the thing I find most difficult is the order in which the various functions are written, it's definitely an area I need to understand more. I will also dive into the LET function at some stage and give that formula a test run.

Appreciate the help @BSALV and @KRice.

Cheers,
 
Upvote 0

Forum statistics

Threads
1,216,104
Messages
6,128,856
Members
449,472
Latest member
ebc9

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top