Excel function to choose a value greater than or less that a particular value in cell - excel

I have a data set something like this
Units Price
1 15
100 10
150 9
200 8
50000 7
I need the output as Price with respect to quantity.
Example- If Input value is 90 it should give price as 15
If input is 210 it should give value as 8.
However,sadly I cannot use IF statement.
Thanks in advance.

You can use a combination of INDEX and MATCH
=INDEX(B1:B5,MATCH(lookup_value,A1:A5,1))
This assumes Units are in column A and Price is in column B
Make sure you understand both functions:
INDEX
MATCH - particularly the reason for the ,1) at the end

You can also use VLOOKUP. This is probably a bit easier although INDEX/MATCH is more versatile:-
=VLOOKUP(Lookup_value,$A$2:$B$6,2,TRUE)

Related

Excel - Find row with conditional statement in XLOOKUP

I'm trying to use XLOOKUP to find a value based on user inputs.
The table looks like this:
Type Start End 33 36 42 48
---------------------------------------
4002 1 7 1.17 1.34 1.5 1.84
4002 8 12 1.84 1.67 2.1 3.45
User selects type, number (can be between start and end), and 33-48
I can nest an XLOOKUP to specify the 3 criteria
=XLOOKUP(*type* & *number* , *typeRange* & *numberRange* ,XLOOKUP(*33-48* , *33-48Range* , *ResultRange* ))
And I can find if a value is between the columns
=IF(AND(*number*>=*Start*,*number*<=*End*),TRUE,FALSE)
Can I combine the two? The data is redundant for numbers 1-7, and I would like to keep the table small.
You sort-of can combine them. I have added a couple of extra rows to the table to see what would happen if you had different Type values as well as number values. The problem then is that if you used approximate match and put in a number like thirteen which is out of range, you might end up getting the next row of the table which would be incorrect. One way round it would be to use the options in Xlookup to search for next-smaller-item in the Start column and next-larger-item in the End column and see if the results match:
=IF(XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(B2:B7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,-1)=XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(C2:C7,"00"),
XLOOKUP(K2,D1:G1,D2:G7),,1),XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(C2:C7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,1),"Error")
If you have some checks in place which make it impossible for number to be out of range, then you can simplify the formula:
=XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(B2:B7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,-1)
or
=XLOOKUP(I2&TEXT(J2,"00"),A2:A7&TEXT(C2:C7,"00"),XLOOKUP(K2,D1:G1,D2:G7),,1)

Excel formula for greater than but less than with several tiers

I have a few hundred rows of data, and each has a number between 1 and 200, and I'd like to put them in categories of 1-5 depending on where that number is.
The categories look like this:
Zones Min Max
1 0 35
2 35 60
3 60 85
4 85 110
5 110 200
I want to assign it a Zone if it is greater than the Min, but less than the Max.
I have 2 formulas I've been working with to solve it. One is a nested IF AND statement:
=IF(A1<=35,1,IF(AND(A1<=60,A1>35),2,IF(AND(A1<=85,A1>60),3,IF(AND(A1<=110,A1>85),4,IF(AND(A1<=200,A1>110),2,"TOO BIG")))))
The 2nd formula attempts to use a SUMPRODUCT function:
=INDEX($C$2:$C$6,SUMPRODUCT(--(A1<=$E$2:$E$6),-- (A1>$D2:$D$6),ROW($2:$6)))
Rather than have to continue to adjust the numeric values manually, I set them as absolutes, which is why this formula is slightly different. The E column is the Max value set, and the D is the Min value set.
Any help would be appreciated!
Use this:
=MATCH(A1,{0,35,60,85,110})
Another way is to use VLOOKUP and you just need to set the min number:
=VLOOKUP(D2,$A$2:$B$6,2,1)
The key is the 4th parameter needs to set to 1 which means TRUE. It will find the closest value and return the zone for you.
But noticed that you have overlaps like 35 or 60 etc. that you will need to adjust your value column.

Excel IF and or value range

I have a formula that currently works pretty well for the most part. It originally was a scoring factor of 90%-100= 5, and 85% to 89.99% = 4 and 80% to 84.99% = 3 and so on. This is represented using the formula below:
=IF($B10>=90%,5,IF($B10>=85%,4,IF($B10>=80%,3,IF($B10>=75%,2,IF($B10<=74.99%,1)))))
So the new requirement came down as follows:
Range value picture
95 to 100% = 5
85 to 89.99% or 101.1 to 105% = 4
80 to 89.99% or 105.1 to 110% = 3
75 to 79.99% or 110.1 to 115% = 2
Less than 74.9 = 1
So the dilemma I'm in is I have not been able to figure out how to create a range for values 2, 3 and 4 to be either or side for the scoring value to become true. So score value 4 should be the ranges of 85% through 89.99% OR 101.1% through 105% to be true.
Does anyone have any ideas on how to restructure this to include the ranges so that if either range is true it would show the correct scoring values? Thanks in advance for your help.
Instead of nested ifs consider using a table then use a VLOOKUP to find the correct value:
I created this table:
Then I can use this formula to get the proper score:
=VLOOKUP(B10,E:F,2,TRUE)
This method has the advantage of being able to easily expand to accomadate new rules. The only caveat is that your table must be sorted on the first column to get the proper return.

Value between a range of values

Having this:
Class Min Max
Alfa 0 16.5
Beta 16.5 18.5
Charlie 18.5 25
Delta 25 30
And this:
Value X
35.52600894
26.27816853
29.53159178
29.84528548
26.77130341
25.07792506
19.2850645
42.77156244
29.11485934
29.5010482
19.30982162
I want a cell to have something like an IF statement (it's got a few more values in it, not this small, it has 8 class). An IF statement this long would probably not work (IF limit of 7) and is an ugly way of doing it. I was thinking of using hlookup, but I'm not sure if that's the best bet.
I can also swap the columns within a table, so I could have "Min| Max| Class"
X values are in a column.
Basically: =IF(X>=0 && X<16.5, Alpha, IF(X>=16.5 && X<18.5, Beta, IF(...
I think you mean VLOOKUP and would be much better way to go.
Make a Ranges sheet like this
Min Class
0 Alfa
16.5 Beta
18.5 Charlie
25 Delta
30.5 Unidentified
In your detail sheet use formula "=VLOOKUP(A2,Ranges!A:B,2,TRUE)" [The True is important]
And you get
Value X Class
35.52600894 Unidentified
26.27816853 Delta
29.53159178 Delta
29.84528548 Delta
26.77130341 Delta
25.07792506 Delta
19.2850645 Charlie
42.77156244 Unidentified
29.11485934 Delta
29.5010482 Delta
19.30982162 Charlie
With your Max range named MaxVal and your Class range named Class, please try:
=IF(A2>30,"",INDEX(Class,MATCH(A2,MaxVal)))
(adjust references to suit).
=MATCH() here is using the match_type parameter of 1: “The MATCH function will find the largest value that is less than or equal to value. You should be sure to sort your array in ascending order.
If the match_type parameter is omitted, the MATCH function assumes a match_type of 1.”
Any X value greater than 30 returns a blank ("") but text may be inserted to suit (eg "Unidentified" instead of "").
The formula could be simplified by removing the error trap, if a row were inserted immediately under the labels with Alpha under Class and 0 under Max. Also by removing the condition, in a similar way.
It is not necessary to specify both bounds of each range.
INDEX/MATCH was chosen rather than say VLOOKUP for reasons as given here.
PS For the Greek *alpha*bet α is usually Alpha.
Edit re clarification
The easiest fix for 25 is Delta rather than Charlie may be to deduct a small amount from each Max value, eg change 25 to =25-1/1E100.

Excel: Find the minimal value in a column

An Excel table consists of two columns (e.g., A1:B5):
0 10
1 20
3 30
2 20
1 59
I need to get the minimal value in column B for which the corresponding value in column A is greater than zero. In the above example it should be 20.
I tried using various combinations of INDEX(), MIN(), IF(), ROW(), array formulas, etc. - but I just can't figure out how to do it. :-( Any help would be appreciated.
Grsm almost had it
if you enter the following formula in C1 as an array (Ctrl+Shift+End)
=MIN(IF(A1:A5>0,B1:B5))
That should do the trick.
I think you have to make an extra column..
A B C D
0 10 false 20
1 20 20
3 30 30
2 40 40
1 50 50
column C : =IF(A1>0;B1)
cell D1: =MIN(C1:C5)
You need to do it in 2 stages
First use the MIN function to find the minimum
Then take that answer and use the LOOKUP function to select the row and column that you need.
Check the "Minimum And Maximum Values In A Range" example in http://www.cpearson.com/Excel/excelF.htm (you can download the same as well from the same section)
HTH
This is not identical, but very similar: Excel VBA - Find minimum of list of values?

Resources