Does INDEX-MATCH lookup system have limitations with ascending/descending lists? - excel

Solved it was as stated at the 1st comment link, -1 for [match_type] must be used with an ascending order look up list, and viceversa for 1, which requires a descending order list.
TL;DR summary: The [match_type] entry for the MATCH function seems to be a variable I must enter depending on whether my list of lookup numbers is ascending or descending, is this the case and hence a limitation or am I simply using it wrong?
I am trying to evaluate readings from measurements. To do this evaluation I must rely on theoretical values calculated to compare the actual values to a perfect situation. To do this I have a defined table with all the calculated values. I then use the INDEX-MATCH system to lookup the closest theoretical value (for comparison) to my experimental one.
FYI the INDEX-MATCH is structured as follows:
=INDEX(Return_value_range, MATCH(Lookup_value, Lookup_value_range, [match_type]))
Below is an example of the beginning of my table:
A B C
1 C O Zr
2 5.707 7.602 86.691
3 5.719 7.587 86.694
4 5.730 7.572 86.697
5 5.742 7.557 86.701
6 5.753 7.543 86.704
7 5.765 7.528 86.707
8 5.777 7.513 86.711
[ascending] [descending] [descending]
Here is an example of my values:
D E F G H
1 Run O C Zr (O index) Zr (C index)
2 1 2.90 9.23 [formula] [formula]
3 2 3.57 9.72 [formula] [formula]
4 3 2.86 9.45 [formula] [formula]
So my formula to lookup the Zr value in cell G2 based off of the experimental O value in E2 would be as follows
=INDEX(B2:BXXX,MATCH(E2,C2:CXXX,-1))
This returns the values correctly however here is where it seems I run into an inherent limitation: for the formula in E2 I MUST put the [match_type] value at the end of the MATCH function as -1 otherwise it returns me either a #N/A value.
Similarly this is also the case when entering the same formula to lookup the Zr value based off of the experimental C value in cell H2, except that the [match_type] value has to be +1 as follows:
=INDEX(A2:AXXX,MATCH(F2,C2:CXXX,1))
The [match_type] part of the MATCH function can have 3 value, as explained here, which are:
0 for an Exact Match.
-1 for a Nearest Greater Than Match.
1 for a Nearest Less Than Match.
My conclusion is that I have to choose the [match_type] based off whether the lookup_value_range list is either ascending or descending.
Question: Is my observation a limitation of the system or an incorrect use of mine of the technique?

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

Presenting a value based on number or text in cell

I have a list of 4 values in Sheet1 and 4 values in Sheet2.
In Sheet3 I will combine a random selection of these numbers and return the value in a column. (edit: no random selection from Excel, its a part picked from a bucket)
(A fifth column in Sheet3 will be used to do calculations with ValueS1 and ValueS2)
Sheet1
NumberS1
ValueS1
1
17.10
2
17.20
3
17.12
4
17.15
Sheet2
NumberS2
ValueS2
1
16.10
2
16.20
3
16.12
4
16.15
Sheet3
NumberS1
NumberS2
ValueS1
ValueS2
1
3
17.10
16.12
2
2
17.20
16.20
4
1
17.15
16.10
3
4
17.12
16.15
What kind of function can give the desired return?
I have looked into examples using "Indirect" but cannot see how they will solve my problem.
for the randomization: =ROUNDUP(RAND()*4,0)
rand() gives you a number between 0 and 1, so rand()*4 gives you a number between 0 and 4.
roundup(x,y) round up the number x with y digits you want to round the number up to (in our case 0).
for import the right number from sheet 1 or 2: =VLOOKUP(A1,Sheet1!A1:B2,2,0)
A1 - The value you look for in sheet 1 or 2.
Sheet1!A1:B4 - The array he look for your value on the firs column, always on the first column.
2 - The column you want to import the value from. (because we write an array of tow columns. we can write here only 1 or 2)
0 - it's an Optionally index (0 or 1). o is if you want an exact match of the return value.
Regular Lookup could do:
=LOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5) in Sheet3!C2
And
=LOOKUP(B2:B5,Sheet2!A2:A5,Sheet2!B2:B5) in Sheet3!D2
Note that LOOKUP will give the result to the closest match smaller than the search value.
Or VLOOKUP:
=VLOOKUP(A2:A5,Sheet1!A2:B5,2,0) / =VLOOKUP(B2:B5,Sheet2!A2:B5,2,0)
VLOOKUP will error if the value is not found (the way used above). It uses arguments like this:
=VLOOKUP(What you want to look up, where you want to look for it, the column number in the range containing the value to return, return an Approximate or Exact match – indicated as 1/TRUE, or 0/FALSE)
Office 365 has XLOOKUP which combines the logic of the two above and some more:
=XLOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5,"value not found",0)
XLOOKUP uses the following arguments:
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Sum of the greatest value in one column, plus the sum of the other values in another column

Consider the following sheet/table:
A B
1 90 71
2 40 25
3 60 16
4 110 13
5 87 82
I want to have a general formula in cell C1 that sums the greatest value in column A (which is 110), plus the sum of the other values in column B (which are 71, 25, 16 and 82). I would appreciate if the formula wasn't an array formula (as in requiring Ctrl + Shift + Enter). I don’t have Office 365, I have Excel 2019.
My attempt
Getting the greatest value in column A is easy, we use MAX(A1:A5).
So the formula I want in cell C1 should be something like:
=MAX(A1:A5) + SUM(array_of_values_to_be_summed)
Obtaining the values of the other rows in column B (what I called array_of_values_to_be_summed in the previous formula) is the hard part. I've read about using INDEX, MATCH, their combination, and obtaining arrays by using parenthesis and equal signs, and I've tried that, without success so far.
For example, I noticed that NOT((A1:A5 = MAX(A1:A5))) yields an array/list containing ones (or TRUEs) for the relative position of the rows to be summed, and containing a zero (or FALSE) for the relative position of the row to be omitted. Maybe this is useful, I couldn't find how.
Any ideas? Thanks.
Edit 1 (solution)
I managed to obtain what I wanted. I simply multiplied the array obtained with the NOT formula, by the range B1:B5. The final formula is:
=MAX(A1:A5) + SUM(NOT((A1:A5 = MAX(A1:A5))) * B1:B5)
Edit 2 (duplicate values)
I forgot to explain what the formula should do if there are duplicates in column A. In that case, the first term of my final formula (the term that has the MAX function) would be the one whose corresponding value in column B is smallest, and the value in column B of the other duplicates would be used in the second term (the one containing the SUM function).
For example, consider the following sheet/table:
A B
1 90 71
2 110 25
3 60 16
4 110 13
5 110 82
Based on the above table, the formula should yield 110 + (71 + 25 + 16 + 82) = 304.
Just to give context, the reason I want such a formula is because I’m writing a spreadsheet that automatically calculates the electric current rating of the short-circuit protective device of the feeder of a group of electric motors in a house or building or mall, as required by the article 430.62(A) of the US National Electrical Code. Column A is the current rating of the short-circuit protective device of the branch-circuit of each motors, and column B is the full-load current of each motor.
You can use this formula
=MAX(A1:A5)
+SUM(B1:B5)
-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)
Based on #Anupam Chand's hint for max-value-duplicates there could also be min-value-duplicates in column B for corresponding max-value-duplicates in column A. :) This formula would account for that
=SUM(B1:B5)
+(MAX(A1:A5)-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1))
*SUMPRODUCT((A1:A5=MAX(A1:A5))*(B1:B5=AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)))
Or with #Anupam Chand's shorter and better readable and overall better style :)
=SUM(B1:B5)
+(MAX(A1:A5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
*COUNTIFS(A1:A5,MAX(A1:A5),B1:B5,MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
The explanation works for bot solutions:
The SUM-part just sums the whole list.
The second line gets the max-value for column A and the corresponding min-value of column B for the max-values in column A and adds or subtracts it respectively.
The third line counts, how many times the corresponding min-value for the max-value occurs and multiplies it with the second line.
Can you try this ?
=MAX(A1:A5)+SUM(B1:B5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5))
What we're doing is adding the max of A to all rows of B and then subtracting the min value of B where A is the max.
If you have Excel 365 you can use the following LET-Formula
=LET(A,A1:A5,
B,B1:B5,
MaxA,MAX(A),
MinBExclude, MINIFS(B,A,MaxA),
sumB1,SUMPRODUCT(B*(A=MaxA)*(B<>MinBExclude)),
sumB2,SUMPRODUCT(B*(A<>MaxA)),
MaxA +sumB1+sumB2
A and B are shortcuts for the two ranges
MaxA returns the max value for A (110)
MinBExclude filters the values of column B by the MaxA-value (25, 13, 82) and returns the min-value of the filtered result (13)
sumB1 returns the sum of the other MaxA values from column B (26 + 82)
sumB2 returns the sum of the values from B where value in A <> MaxA (71 + 60)
and finally the result is returned
If you don't have Excel 365 you can add helper columns for MaxA, MinBExclude, sumB1 and sumB2 and the final result

Finding Closest Available Non-0 or NA value

I have an excel dataset that looks something like this:
Variable 1.2018 2.2018 3.2018 ...
A 4 5 8 ...
B 4 5 n.a ...
C 4 0 5 ...
D 4 n.a 9 ...
On a separate sheet I have a summary table that extracts numbers from this dataset using an index match function.
However, I am hoping for my function to not take on 0 or n.a values. Take for example, ideally, I would wish to compare growth between A and B at 3.2018, variable B contains n.a and wouldn't be very useful. In this case I would rather then compare between A and B at 2.2018 instead.
Variable 3.2017 3.2018 Growth
A 5 8 60%
B 5 n.a #VALUE
Variable 2.2017 2.2018 Growth
A 3 5 66%
B 4 5 25%
In the other case, say I were comparing between C and D. If I were to compare them at 3.2018, I would have no problems because they do not contain 0 or n.a values. However if I were to compare them at 2.2018, then I would want the formula to take the values from 1.2018 instead.
In the above cases, I would also like to know when it is the case that the values do not come from the 'ideal' time frame.
I tried to do an "if" before the index match but in the case of the first example it will only change the number of B and not A. It also does not work if I have 2 or more 0's or na's in a row.
Do an IF() function, wherein you check if either of your 3.2018 values are either 0 or #N/A (assuming these are actually the excel value of #N/A, and not a string representation like "n.a.")... if either are true, use the 2.2018 value otherwise use the 3.2018 values
=IF( OR(IFNA(D3=0, TRUE), IFNA(D2=0, TRUE)), C2=C3, D2=D3)

Return corresponding date of max value

I'm looking for a formula which will give me the date of the last version of the order.
To illustrate, the sheet looks as follows:
A B C
1 Sales Order Version Date
2 SO#12345 1 21/02/2013
2 SO#12345 2 28/04/2013
3 SO#12345 3 04/08/2013
4 SO#12345 4 27/09/2013
5 SO#54321 1 02/03/2014
6 SO#54321 2 31/03/2014
7 SO#54321 3 07/10/2014
8 SO#54321 4 13/12/2014
So I would like to get the date of SO#12345, version 4 (29/09/2013).
I've tried several combinations of INDEX, MATCH, IF and MAX functions, but I can't seem to get the right value.
It either gives me the corresponding date of the highest value in the version column or it gives me the correct version number, but I can't make it show the appropriate date.
I did use CTRL+SHIFT+ENTER for these formulas, so they are executed as a matrix function.
Again, assuming the Order Number is in E2, try:
=LOOKUP(1,0/FREQUENCY(0,1/(1+(A2:A8=E2)*B2:B8)),C2:C8)
Regards
If the versions are listed in order for each Sales Order numberyou can use LOOKUP like this:
=LOOKUP(2,1/(A$2:A$8=E2),C$2:C$8)
Where E2 contains a specific order number
....or you can use the order number directly
=LOOKUP(2,1/(A$2:A$8="SO#12345"),C$2:C$8)

Resources