VLookup with Multiple Ranges - excel

I'm trying to make a formula that would do the following: There are say 10 categories 1-10, given a number x and y, the line is in category 3 if and only if x is between 1 and 2 and y is between 5-7 for example. I don't know how to use VLookup given the multiple conditions and the two ranges that are completely different and not in a sequential order.
I tried using index match:
=INDEX(B5:B15,MATCH(1,IF(AND(K5>=C5:C15,K5<=D5:D15),1,0)*IF(AND(L5>=E5:E15,L5<=F5:F15),1,0),0))
but this returns an error where column B are the categories, K5 and L5 are x and y respectively and column C is the lower bounds for x per category with D as upper bounds and same for E and F for y.
Here's a mock representation of the data and rules:
Data
x y category
1.2 12 1
1.5 5 2
0.98 23 3
.
.
.
Rules
Category X-LB X-UB Y-LB Y-UB
1 1 2 9 15
2 1.5 1.7 1 9
3 0.8 1 20 23
.
.
.
LB is lower bound and UB is upper bound. For example given x and y above using the rules table we find the expected return column.
Thank you,

If you have only category which will fit the bill in each case, one way is to use SUMPRODUCT.
Formula in C2 and down is
=SUMPRODUCT(($B$10:$B$12<=A2)*($C$10:$C$12>=A2)*($D$10:$D$12<=B2)*($E$10:$E$12>=B2)*($A$10:$A$12))

In M5, copied down :
=INDEX($B$5:$B$15,MATCH(1,INDEX(($K5>=$C$5:$C$15)*($K5<=$D$5:$D$15)*($L5>=$E$5:$E$15)*($L5<=$F$5:$F$15),0),0))
Or,
Another shorter option.
Using SUMIFS function, formula in M5 copied down :
=SUMIFS($B:$B,$C:$C,"<="&$K5,$D:$D,">="&$K5,$E:$E,"<="&$L5,$F:$F,">="&$L5)

Related

TRUE/FALSE ← VLOOKUP ← Identify the ROW! of the first negative value within a column

Firstly, we have an array of predetermined factors, ie. V-Z;
their attributes are 3, the first two (•xM) multiplied giving the 3rd.
f ... factors
• ... cap, the values in the data set may increase max
m ... fixed multiplier
p ... let's call it power
This is a separate, standalone array .. we'd access with eg. VLOOKUP
f • m pwr
V 1 9 9
W 2 8 16
X 3 7 21
Y 4 6 24
Z 5 5 25
—————————————————————————————————————————————
Then we have 6 columns, in which the actual data to be processed is in, & thereof derive the next-level result, based on the interaction of both samples introduced.
In addition, there are added two columns, for balance & profit.
Here's a short, 6-row data sample:
f • m bal profit
V 2 3 377 1
Y 2 3 156 7
Y 1 1 122 0
X 1 2 -27 2
Z 3 3 223 3
—————————————————————————————————————————————
Ultimately, starting at the end, we are comparing IF -27 inverted → so 27 is within the X's power range ie. 21 (as per the first sample) .. which is then fed into a bigger formula, beyond the scope of this post.
This can be done with VLOOKUP, all fine by now.
—————————————————————————————————————————————
To get to that .. for the working example, we are focusing coincidentally on row5, since that's the one with the first negative value in the 'balance' column, so ..
on factorX = which factor exactly is to us unknown &
balance -27 = which we have to locate amongst potentially dozens to hundreds of rows.
Why!?
Once we know that the factor is X, based on the * & multiplier pertaining to it, then we also know which 'power' (top array) to compare -27, as the identified first negative value in the balance column, to.
Is that clear?
I'd like to know the formula on how to achieve that, & (get to) move on with the broader-scope work.
—————————————————————————————————————————————
The main issue for me is not knowing how to identify the first negative or row -27 pertains to, then having that piece of information how to leverage it to get the X or identify the factor type, especially since its positioned left of the latter & to the best of my knowledge I cannot use negative column index number (so, latter even if possible is out of the question anyway).
To recap;
IF(21>27) = IF(-21<-27)
27 → LOCATE ROW with the first negative number (-27)
21 → IDENTIFY the FACTOR TYPE, same row as (-27)
→ VLOOKUP pwr, based on factor type identified (top array, 4th column right)
→ invert either 21 to a negative number or (-27) to the positive number
= TRUE/FALSE
Guessing your columns I'll say your first chart is in columns A to D, and the second in columns G to K
You could find the letter of that factor with something like this:
=INDEX(G:G,XMATCH(TRUE,INDEX(J:J<0)))
INDEX(J:J<0) converts that column to TRUE and FALSE depending on being negative or not and with XMATCH you find the first TRUE. You could then use that in VLOOKUP:
=VLOOKUP(INDEX(G:G,XMATCH(TRUE,INDEX(J:J<0))),A:D,4,0)
That would return the 21. You can use the first concept too to find the the -27 and with ABS have its "positive value"
=VLOOKUP(INDEX(G:G,XMATCH(TRUE,INDEX(J:J<0))),A:D,4,0) > INDEX(J:J,XMATCH(TRUE,INDEX(J:J<0)))
That should return true or false in the comparison

Excel Formula for finding Y maximum in a given X range

I have an XY table in excel. I would like to find the maximum Y value in a given X range. Example data given below. What equation can I use, in an unrelated cell, to output the max Y value in between the X range 2:6
X
Y
1
4
2
7
3
0
4
8
5
4
6
3
Using MAXIFS:
=MAXIFS(B:B,A:A,">=2",A:A,"<=6")
As noted by #ScottCraner, if your version of Excel does not support MAXIFS, see this thread for alternatives.
I understand your question so:
you want the biggest number in column Y which also is present in X
=MAXIFS(B2:B7;B2:B7;">="&MIN(A2:A7);B2:B7;"<="&MAX(A2:A7))

Distributing data with lower and upper boundaries in Excel

Here's a link to a screenshot with the formula used in Column B and some sample data
I have a spreadsheet with 48 rows of data in column A
The values range from 0 to 19
The average of these 48 rows = 8.71
the standard deviation of the population = 3.77
I've used the STANDARDIZE function in excel in column B to return the Z-score of each item in column A given that I know the mean (8.71), std dev (3.77), and x (whatever is in column A).
For example (row 2) has:
x = 2
z = -1.779
Using the z value, I want to create an lower (4) and upper (24) boundary and calculate what the value would be in this 3rd column.
Essentially, if x = 0 (min value), then z = -2.3096, and columnC = 4 (lower boundary condition)
Conversely, if x = 19 (max value), then z = 2.9947, and columnC = 19 (upper boundary condition)
and then all other values between 0 to 19 would be calculated....
Any ideas how I can accomplish this with a formula in the column C?
So if your lowest original value is 0 and your highest is 19 and you want to re-distribute them from 4 to 24 and we assume that both are linear that means:
Since both are linear we have to use these formulas:
we develope the first to c so we get
and replace the c in the second equation with that so we get
and develope this to m as follows
If we put this togeter with our third equation above we get:
So we finally have equations for m = and c = and we can use the numbers from our old and new lower and upper bound to get:
you can use these values with
where x is are your old values in column A and y is the new distributed value in column B:
Some visualization if you change the boundaries:
Idea for a non-linear solution
If you want 4 and 24 as boundaries and the mean should be 12 the solution cannot be linear of course. But you could use for example any other formula like
So you can use this formula for column D y2 with the following values a, b, c as well as calculating the mean, min and max over column D y2.
Then use the solver:
Goal is: Mean $M$15 should be 12
secondary conditions: $M$16 = 4 (lower boundary) and $M$17 = 24 (upper boundary)
variable cells are a, b and c: $M$11:$M$13
The solver will now adjust the values a, b and c so that you get very close to your goal and to get these results:
The min is 4 the max is almost 24 and the mean is almost 12 that is probably the closest you can get with a numeric method.

Solving a math equation in excel through two variables

w=[1/mn(m^2+n^2)^2)]{sin(m*pi/2)sin(n*pi/2)}
where m and n varies from 1 to 11.
for m=1, n=1,3,5,7,9,11.
for m=2, n=1,3,5,7,9,11.
for m=3, n=1,3,5,7,9,11.
and so on.
Instead of 36 sets of combinations, I need one formula to calculate the set of these 36 combinations and get respective values of w.
Please help me with this equation. I need to solve it in excel.
P.S I'm beginner.
You may create column and rows with heading values of n and m respectively, and calculate the value of w at their intersection. For auto-completion of formula by dragging, you will have to use $ symbol for referencing. See the representation below:
m\n 1 3 5 7 9 11
1 w(1,1) w(1,3) w(1,5) w(1,7) w(1,9) w(1,11)
2 w(2,9) w(3,9) ... so on
3 ...
4
5
6
.
.
Instead of numbers above in w(m,n) use references of column while dragging with a $ sign so that the header row does not change.
EDIT: You need to type the formula only once in at the intersection of (1,1)

Excel replace numbers with custom unequal ranges

Suppose I have the following data
Name Output
A 0.1
B 7
C 0.4
D 0.9
E 1.1
F 12
G 22
I would like replace the output variable by custom ranges:
Name Output Output_2
A 0.1 0m-0.3m
B 7 6y-10y
C 0.4 0.4m-0.6m
D 0.9 0.7m-1y
E 1.1 1y-5y
F 12 11y-20y
G 22 21y-40y
Right now, I am doing this (a long list of nested IFs)
=IF([#Tenor]<= 0.25, "0m-3m", IF([#Tenor]<=0.5, "4m-6m", IF([#Tenor] <= 1, "7m-1y",IF([#Tenor]<=5,"2y-5y",IF([#Tenor]<=10,"6y-10y",IF([#Tenor]<20,"11y-20y",IF([#Tenor]<40,"20y-40y")))))))
and it works but I am concerned that as the number of ranges increases, this will be painful to write. I was hoping I could write down a range somewhere and ask excel to look it up and do some case type thing.
Let's assume your first three columns are A, B and C (like in the second code block you posted). Add the following data into columns E and F (this will be your mapping data):
Output Output2
0 0m-3m
0.25 4m-6m
0.5 7m-1Y
1 2y-5y
5 6y-10y
10 11y-20y
20 20y-40y
40 20y-40y
Then write the following formula into C2 cell and drag it down:
=INDEX($F:$F,MATCH(B2,$E:$E,1))
UPDATE: you can do this even simpler with approximate VLOOKUP:
=VLOOKUP(B2,$E:$F,2,1)

Resources