Finding Closest Available Non-0 or NA value - excel

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)

Related

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])

EXCEL Sum up points based on placements (combine VLOOKUP and SUM)

e.g. I have a list of race results:
A B C D E F...
NAME P. RACE1 RACE2 RACE
abc =? 1 3 3
bcd 3 2 4
cde 4 4 2
def 2 1 1
and another sheet with points for each result:
A B
PLACE POINT
1 10
2 5
3 2
4 1
Is it possible to get the total points in sheet1 column B based on the race results in column C-E..?
Is it a connection from VLOOKUP and SUM?
Yes, that's possible. You can use a SUMPRODUCT formula for that. You may use this one in column B:
=SUMPRODUCT((C2:E2=$A$13:$A$16)*$B$13:$B$16)
Your result will look like this:
This is an array function. The term C2:E2=$A$13:$A$16 will check for race 1 to 3 if it was 1st, 2nd, 3rd or 4th place. This will result in an "imaginary" array of TRUE and FALSE. For name "abc", it will look like that.
Those results are then multiplied with the points from B13:B16 and the sum is formed.
In Excel O365, one could use:
Formula in B2:
=SUM(VLOOKUP(C2:E2,H$2:I$5,2))

Retrieve column 4 from Column 2 and 3 which contains minimum and maximum conditions along with Column 1 which is a separate value?

Hello I have a table shown below where I have letters in column 1, and min and max ranges for column 2 and 3. I am trying to retrieve the final number in column 4.
I know I can use a VLOOKUP and set the range as TRUE to get the last column. However, how would I factor in multiple columns/criteria to find match the correct range with the correct letter.
For example, I can would like to get value 4 from the last column. I would have to match with "B" and it would be between 0 and $50,000.
A 0 $50,000 1
A $50,001 $100,000 2
A $100,001 $250,000 3
B 0 $50,000 4
B $50,001 $100,000 5
B $100,001 $250,000 6
C 0 $50,000 7
C $50,001 $100,000 8
C $100,001 $250,000 9
Thank you!
Two ways:
If the pattern is the same as to the breaks of the dollar amounts then use this:
=INDEX(D:D,MATCH(G1,A:A,0)+MATCH(H1,$B$1:$B$3)-1)
Where MATCH(G1,A:A,0) returns the first row where the ID is located and MATCH(H1,$B$1:$B$3) finds the relative location of the price in the first pattern. Change $B$1:$B$3 to encompass the whole pattern.
If the patterns are different then you can use this:
=SUMIFS(D:D,A:A,G1,B:B,"<=" & H1,C:C,">=" & H1)
One more for the future when Microsoft releases FILTER():
=FILTER(D:D,(A:A=G1)*(B:B<=H1)*(C:C>=H1))
This is entered normally and does not matter the pattern.

How to get a column name based on function

Suppose I have a dataset:
A B C Final
1 2 3 C
4 5 6 C
I want final to return the column name of the max value. In the example above, 3 and 6 are the highest values, so columns C will be returned in the 'Final' column.Is there an efficient way/formula you can use to get the column names without using VBA? the real dataset containts 60 columns.
I would try something like this to get the column letter.
=SUBSTITUTE(ADDRESS(1,MATCH(MAX(A3:C3),A3:C3,0),4),1,"")
If you want the header, I think there's an easier way, but the extension from this would be
=INDIRECT(SUBSTITUTE(ADDRESS(1,MATCH(MAX(A3:C3),A3:C3,0),4),1,"")&1)
For the header, the better way
=INDEX(A1:C1,1,MATCH(MAX(A3:C3),A3:C3,0))
HLOOKUP is a way without VBA, but sadly HLOOKUP does only search in the first row of the array, so you should add the "title column" at the bottom
A B C Final
1 2 3 <formula1>
4 5 6 <formula2>
A B C
If the dataset starts at first corner, Formula1 would be :
=HLOOKUP(MAX(A2:C2);A2:C4;2;FALSE)
Formula2 will be
=HLOOKUP(MAX(A3:C3);A3:C4;1;FALSE)
etc...
=HLOOKUP(MAX($A3:$C3);$A3:$C$4;<manual change here backward>;FALSE)
You can use the vector form of the LOOKUP function.
If your first row, with A B C, are the labels, then:
=LOOKUP(2, 1/(MAX(A2:C2)=A2:C2),$A$1:$C$1)

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

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?

Resources