Issue with formula including LARGE() + multiple criterias - excel

At the moment my formula looks for a LARGE number in column D, which is greater than number in K4, however if the number in K4 is greater than the LARGEST number in col D I get an error #NUM!
=IF(AND($K$4="",$D$5=""),"Not Reported",IF(AND($K$4="",$D$5<>""),"Missing DATA",IF(AND($K$4<>"",$D$5<>""),INDEX($E$5:$E$23,MATCH((SMALL($D$5:$D$23,COUNTIF($D$5:$D$23,""&$K$4)+1)),$D$5:$D$23,0),1))*1-$K$4/SUM(LARGE($D$5:$D$23,COUNTIF($D$5:$D$23,">"&$K$4)+1)+SMALL($D$5:$D$23,COUNTIF($D$5:$D$23,""&$K$4)+1))))+INDEX($E$5:$E$23,MATCH("P98",$A$5:$A$23,0)))))
Can you advise how to alter it, so if the above occurs, instead of taking the number from K4 into consideration, simply replace it with whatever the LARGEST number in col D is and finish the rest of calculations [embedded in the formula]. Appreciate your help.
PS. IFERROR is not an option (it doesn't solve this)
SAMPLE DATA [where the error occurs]:
VALUE OF $K$4
250000
COLUMN A
PERCENTILE
P10
P20
P30
P40
P50
P60
P70
P80
P90
P91
P92
P93
P94
P95
P96
P97
P98
P99
P100
COLUMN D
NUMBER
3500
4096.79
10000
13500
15000
18299.46
25000
39000
50000
50000
50000
50000
200000
200000
200000
200000
200000
200000
200000
COLUMN E
VOLUME
2
2
1
2
1
2
2
1
2
0
0
0
1
0
0
0
0
0
0

I can't give an exact answer since I don't have exact detail about what you're trying to do, however it sounds like you want to do something like this:
=max(k4, d:d)
So: If K4 is the same are bigger than the largest number in Column D, then use K4. Otherwise, use the biggest number in Column D.
More Information:
Office.com : MAX Function
MAX vs MAXA vs LARGE and MIN vs MINA vs SMALL Functions in Excel

So, this works for me:
=IF($J$4="",F27,(IF(J4>=MAX(B5:B23),(INDEX($C$5:$C$23,MATCH((SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&IF(J4>MAX(B5:B23),MAX(B5:B23),J4))+1)),$B$5:$B$23,0),1))*(1-((IF(J4>MAX(B5:B23),MAX(B5:B23),J4))/SUM(LARGE($B$5:$B$23,COUNTIF($B$5:$B$23,">"&(IF(J4>MAX(B5:B23),MAX(B5:B23),J4)))+1)+SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&(IF(J4>MAX(B5:B23),MAX(B5:B23),J4)))+1))))+INDEX($C$5:$C$23,MATCH("P98",$A$5:$A$23,0),1),IF(J4<=MIN(B5:B23),INDEX($C$5:$C$23,MATCH((SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,">"&IF(J4<MIN(B5:B23),MIN(B5:B23),J4))+1)),$B$5:$B$23,0),1))*(1-((IF(J4<MIN(B5:B23),MIN(B5:B23),J4))/SUM(LARGE($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&(IF(J4<MIN(B5:B23),MIN(B5:B23),J4)))+1)+SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,">"&(IF(J4<MIN(B5:B23),MIN(B5:B23),J4)))+1))))+INDEX($C$5:$C$23,MATCH("P98",$A$5:$A$23,0),1),(INDEX($C$5:$C$23,MATCH((SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&$J$4)+1)),$B$5:$B$23,0),1))*(1-($J$4/SUM(LARGE($B$5:$B$23,COUNTIF($B$5:$B$23,">"&$J$4)+1)+SMALL($B$5:$B$23,COUNTIF($B$5:$B$23,"<"&$J$4)+1))))+INDEX($C$5:$C$23,MATCH("P98",$A$5:$A$23,0),1)))))
I had to also hedge against the K4 (or J4) value being <MIN(B5:B23)

Related

Finding maximum value in group

I want to create a column of data that finds the largest value in column BD, based on individual values in Column B. I would have thought this equation would work! Anyone have any recommendations??
(first attempt)
=IF(BD3=0,0,SUMIFS($BD$3:$BD3,$B$3:$B3,B3,$BD$3:$BD3,MAX($BD$3:$BD3)))
(Second attempt)
=IF(BD3=MAXIFS($BD$3:$BD3,$B$3:$B3,B3),MAXIFS($BD$3:$BD3,$B$3:$B3,B3),0)
Projectid(B)
cumulative production(BD)
result I want()
1
20
0
1
60
0
1
70
70
2
0
0
2
0
0
3
20
20
4
0
0
5
0
0
6
0
0
7
10
0
7
40
0
7
60
60
this code should work:
=IF(MAXIFS($BD$1:$BD$12,$B$1:$B$12,A1)=BD1,MAXIFS($BD$1:$BD$12,$B$1:$B$12,B1),0)
If you have access to LAMBDA() function then can use below formula at one go.
=LET(a,BYROW(A2:A13,LAMBDA(x,MAXIFS(B2:B13,A2:A13,x))),IF(B2:B13=a,a,0))
Similar to SUMIFS you find MAXIFS
https://support.microsoft.com/en-us/office/maxifs-function-dfd611e6-da2c-488a-919b-9b6376b28883
Then just compare the MAX with the actual row value.
Edit based on your reply:
One way is to start with one operation in the cell first then it is easier to follow.
Your MAXIF should be like this (looking for the max in column B of those rows having the same value in column A as the value of current column A)
=MAXIFS(B$2:B$13;A$2:A$13;A2)
Then compare to B2
So, basically you got it, need just to adjust your second part of the MAXIFS :-)

Return value in cell based on other cells values combination in excel

I have a table in Excel that has the following columns:
My table
dm: Can be 0 or 1
gdr: Can be 0 or 1
smk: Can be 0 or 1
agemin: min age number
agemax: max age number
sbpmin: min sbp number
sbpmax: max sbp number
chlmin: min chl number
chlmax: max chl number
The table is big with all possible combinations.
What i need is a way to find the value in result based on the input of:
dm, gd, smk, age, sbp and chl. As i mention the first 3 can be a 0 or a 1 but the other 3 is a number that must be contain in the range given by the columns min and max.
Has anyone have a clue on how can i solve this?
Thanks,
Using the provided table and assuming the parameters for a lookup are in column M (as shown in the below picture), then the formula in cell M9 and copied right to get the result is:
=IFERROR(INDEX($J$2:$J$4,MATCH(1,INDEX((M2=$A$2:$A$4)*(M3=$B$2:$B$4)*(M4=$C$2:$C$4)*(M5>=$D$2:$D$4)*(M5<=$E$2:$E$4)*(M6>=$F$2:$F$4)*(M6<=$G$2:$G$4)*(M7>=$H$2:$H$4)*(M7<=$I$2:$I$4),),0)),"No matches found")

calculating max value ocurrance for each row formula in excel

A B
1 4
2 5
3 6
100 7
1000 8
how can find number of max value of column values for each row.
=COUNTIF(A1:B5,A1:A5) trying this but this gives 0. I expected 2.
Since; 100 and 1000 are the max values of their rows. need only max value times for rows for A
This is one of the ways you can do it.
Should give you 2.

Finding the interval between demands in an excel forecasting sheet

I want to find a way for Excel to automatically give me the following 'interval':
Month 1 2 3 4 5 6
Demand 1 0 0 1 0 1
'Interval' 0 0 0 3 0 2
The 'interval' shows the amount of months between the demands. Is this doable in some sort of way? I couldnt find a function in Excel to do this. Maybe there is a way in VBA? I need this for the CROSTON forecasting method.
Thank you in advance for your time and effort!
J. Rommers
Count the number of consecutive zeros in the row above and adjust. In B3 enter:
=IF(B2=0,0,COUNTIF($B$2:B2,"=0")-SUM($A$3:A3))
and copy across:
Assuming the 3 columns are A, B and C use:
=MATCH(1,Bn:B1,0)-1
where Bn its the n of C

Best method to calculate provision from a table with provision levels?

I have a table with provision levels.
Sales Provision
0 5%
20 000 22%
100 000 30%
A salesman has 5% provision on the first 20 000, 22% on the next 80 000 and 30% on everything above that.
For example a salesman who sells for 230 000 will have provision
=20 000 * 0,05 + 80 000 * 0,22 + 130 000 * 0,30
How can I express this efficiently with a formula? The formula
Needs to be easy to copy to several rows (where a salesman is described by each row)
Needs to work even if I add more provision levels
Well I can say this works (hopefully) for requirement #2:
Needs to work even if I add more provision levels
But note that I am unsure about requirement #1:
Needs to be easy to copy to several rows (where a salesman is described by each row)
Anyway, with this data:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 57600
100000 0.3
I used this formula in E2:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))+(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1)),E1*B1)
If we break this formula down:
The first basic step is to find the index at which the sale value resides. This is the first lower value compared to the sale value. In your example data this is straight forward because the index is the last in the provision list. However to accommodate sale values that fall within the list range we can use:
MATCH(E1,A:A,1)
where E1 is the sale value and A:A is the sale-provision list.
Using this we can incorporate an INDIRECT to get the desired range we need to work with. In this case A1 to A & Index:
INDIRECT("A1:A"&MATCH(E1,A:A,1))
But even within this range we need to figure out two distinct values:
The provision value index lower than our sale value (i.e. 20 000 * 0.05 + 80 000 * 0.22)
The rest of the provision sale value (i.e. 130 000 * 0.30)
So to get the first value we need to set up an array like this:
(20000 - 0) * 0.05 = 20000*.05 = 1000
(100000 - 20000) * 0.22 = 80000*.22 = 17600
SUM = 18600
That can be done by using
(A2:A3 - A1:A2)*(B1:B2)
But to put that in our INDIRECT formula, that would look like
INDIRECT("A2:A"&MATCH(E1,A:A,1)) <- A2:A3
INDIRECT("A1:A"&MATCH(E1,A:A,1)-1) <- A1:A2
INDIRECT("B1:B"&MATCH(E1,A:A,1)-1) <- B1:B2
(INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Just surround that with a SUMPRODUCT to get the total:
SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Then the second value is just the total sale value subtracted by our index value and multiplied by the corresponding provision rate. So that would be:
(E1-A3)*B3
We actually don't need INDIRECT here, a couple INDEX - MATCH lookups will do:
E1 <- E1
INDEX(A:A,MATCH(E1,A:A,1)) <- A3
INDEX(B:B,MATCH(E1,A:A,1)) <- B3
(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1))
Then adding those to formulas together results in the derived formula I showed earlier.
The final addition however was to add an IFERROR wrapper because if the value is less than the first non-zero provision the INDEX-MATCH and INDIRECT will fail. So in the case of an error that means we just need to multiply the sale value by the first provision rate:
E1*B1
And of course if you add an additional provision row:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 63600
100000 0.30
200000 0.50
Or change the provision:
A B C D E
------------------------------------------
0 0.05 Value 22000
20000 0.22 Total Provision 1440
100000 0.30
The formula will index to the proper provision and calculate it properly.
Also,
Since I know I use commas and decimals in my locale and I realized you don't here is the formula for semi-colon list separator:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1;A:A;1))-INDIRECT("A1:A"&MATCH(E1;A:A;1)-1))*INDIRECT("B1:B"&MATCH(E1;A:A;1)-1))+(E1-INDEX(A:A;MATCH(E1;A:A;1)))*INDEX(B:B;MATCH(E1;A:A;1));E1*B1)

Resources