I'm having an issue with INDEX + MATCH combination:
=INDEX(ALL!$C$1:$I$1,MATCH(TRUE,ALL!C2:I2<>0,0))
At the moment the aforementioned formula does this job to an extent, where if it finds <>0 value in a row it will return header from this specific column. The issue is that the ROW (as above C2:I2) needs to be specified.
I need to vlookup values in the column "A" in sheet "ALL" and based on that, look at corresponding rows between C:I and if the value in that specific row is <>0 then return heading value.
So, in green I would need a formula to pick up numbers from "Data Source" headings, based on value 1 or any value <>0. I'm guessing it all leads somehow to some sort of "vlookup" hybrid.
Any ideas how to combine vlookup in it?
Thanks
If there can only be one '1' per row, I was thinking of this
=SUMIF(INDEX(B:E,MATCH(G2,A:A,0),0),">0",$B$1:$E$1)
Otherwise if there can be more than one '1'
=INDEX($B$1:$E$1,MATCH(TRUE,INDEX(B:E,MATCH(G2,A:A,0),0)>0,0))
to match the first value greater than zero, in this case entered as an array formula.
A simple =SUMIF() formula will do, no other convoluted INDEX() and MATCH() nested formulas required.
Let's presume we have a data-table that starts at B2 and end at
F6, like this:
So now, to comprehend the solution, here's the syntax of SUMIF() formula (Function):
=SUMIF( range, criteria, [sum_range] )
So, what we want to do is:
go over the range of C3:F3 (and each other respective row)
the criteria to when to sum, is when this range contains 1
and we want to sum_range (sum up) fixed array of numbers, so $C$2:$F$2
So the result is (for row 3):
=SUMIF(C3:F3,1,$C$2:$F$2)
and we drag the formula down, producing expected result:
PS: I think this illustrates the point very well, as to why it's important to declare not only what your formula is doing but also, what you're trying to as in whole as there often is a better (easier) way to implement something, that you might not have thought of.
In other words, follow the Minimal, Complete and Verifiable Example
Related
I am trying to make lookups with Multiple Non-Exact Criteria using INDEX-MATCH.
The formual looks like this:
=INDEX(C314:C318;MATCH(1;(D314:D318>=G313)*(E314:E318>=G314);0))
Criterias are: greater or equal to amount X.
Formula works fine, however when using a long list of values, it does not find the best matching value, it finds the first value that matches the criteria.
For example.
Condition 1 is: code "find code equal to 2055516"
Condition 2 is: numerical "find value equal or above 77"
Condition 3 is: alphabetical "find letter equal or greater than H"
In a large dataset where I´ve got many values, it finds only the next best value that matches this criteria. First value that meet that condition would be "80" and "R", however, following values in my dataset, way below, meet much better those criteria with "78" and "I". Problem here is clear I guess.
How can I adapt my formula to look for those much more fitting values that meet my condtions?
Dataset table looks like this:
The formula should return the name "A, B, C, D, E" of the best maching product.
I used a helper column called Helper to rank the letters in Condition 2 alphabetically first using the following formula (drag it down to apply to all rows):
=COUNTIF(Condition_2,"<="&Condition_2)
then use the following formula to find the best match (although it is an array formula it does not need to be confirmed by Ctrl+Shift+Enter):
=INDEX(Product1,MATCH(AGGREGATE(15,6,Helper/((Condition_1>=77)/(Condition_2>="H")),1),Helper,0))
Replace the named ranges in the above formula with the actual ranges in your worksheet.
Replace , with ; as the delimiter in all formulas to suit your system.
EDIT #2
Based on the new scenario, the problem can be solved by AGGREGATE function solely given that the look up value is a number (EAN)
The formula in Cell J2 of my above example is:
=AGGREGATE(15,6,EAN/((DIMENSION=F2)/(LOAD_INDEX>=G2)/(SPEED_INDEX>=H2)),1)
Please note the following are all named ranges which needs to be replaced with the actual range on your workbook:
DIMENSION being B2:B8
LOAD_INDEX being C2:C8
SPEED_INDEX being D2:D8
EAN being A2:A8
If you do not want to show the error #NUM! for no matching result, you can use IFERROR to return a blank cell as shown in Cell J3 of my example. The formula is:
=IFERROR(AGGREGATE(15,6,EAN/((DIMENSION=F3)/(LOAD_INDEX>=G3)/(SPEED_INDEX>=H3)),1),"")
EDIT #3
Please use the following array formula (need to confirm by pressing Ctrl+Shift+Enter) to find the closest match of LOAD INDEX and SPEED INDEX with the help of a Helper column.
{=INDEX(EAN,MATCH(AGGREGATE(15,6,Helper/((LOAD_INDEX/((DIMENSION=G2)/(LOAD_INDEX>=H2)/(SPEED_INDEX>=I2)))=AGGREGATE(15,6,LOAD_INDEX/((DIMENSION=G2)/(LOAD_INDEX>=H2)/(SPEED_INDEX>=I2)),1)),1),Helper/((LOAD_INDEX/((DIMENSION=G2)/(LOAD_INDEX>=H2)/(SPEED_INDEX>=I2)))=AGGREGATE(15,6,LOAD_INDEX/((DIMENSION=G2)/(LOAD_INDEX>=H2)/(SPEED_INDEX>=I2)),1)),0))}
The logic is to first find the closest matches to LOAD INDEX and then find the closest match to SPEED LIMIT from the range with the closest matches to LOAD INDEX.
Again if you do not want to show #NUM! error for no matching result, you can use IFERROR to return the desired result.
Let me know if there is any question. Cheers :)
This might be done through something much smarter, but the following worked for me:
Formula in G2, following the above sample data to return the row with the best match:
=INDEX(A2:A6,MATCH(SMALL(IF(B2:B6-E2>-1,B2:B6-E2+IF(CODE(C2:C6)-CODE(F2)>-1,CODE(C2:C6)-CODE(F2),""),""),1),IF(B2:B6-E2>-1,B2:B6-E2+IF(CODE(C2:C6)-CODE(F2)>-1,CODE(C2:C6)-CODE(F2),""),""),0))
Note Enter as array formula through Ctrl+Shift+Enter
When no criteria matches, it will return an error, you could catch through IFERROR().
I was not sure how to really create the question...
But the problem I am having is this: I have a list (in rows) that relate to a regulatory document, and after trying to create some sort of for loop or elaborate VLookUp/Index formula, I'm requesting help.
For example:
Now I want to use the rows to find the corresponding section in the document. I've already extracted and formatted the compliance document so it is in excel format.
So what I really need is this: a formula or VBA script that can
1. take the compliance number (for example 1A-1 which exist in Cell A3) and go find a cell (in single column D) that has JUST 1A-1, not 1A-1.1, not 1A-1.1.2, etc. and return it to the adjacent cell to 1A-1, for example.
Many thanks ahead of time... I am so lost!! :/
VLOOKUP vs INDEX/MATCH
You can do the 'lookup' two ways (that I'm aware of):
Using VLOOKUP:
The B3 cell contains your formula
=IF(ISERROR(VLOOKUP(A3,C:D,2,FALSE)),"",VLOOKUP(A3,C:D,2,FALSE))
where 'FALSE' is indicating there has to be an exact match and the data doesn't have to be sorted.
Using INDEX with MATCH:
The F3 cell contains the Index/Match formula
=IF(ISERROR(MATCH(A3,C:C,0)),"",INDEX(D:D,MATCH(A3,C:C,0)))
where '0' is indicating there has to be an exact match and the data doesn't have to be sorted.
INDEX/MATCH preferable!?
The MATCH function finds the position (row number if whole column is used) of the found match. This way (there's another) of using the INDEX function uses exactly this found match to return a cell's value in that position (row) in ANY specified column range (column). So they are the ideal combination.
With the VLOOKUP function you have to additionally specify the column index (range_lookup) of a range which could get complicated when the columns aren't adjacent as in this case. Most importantly, the function doesn't work if the lookup data is to the right of the match data.
VLOOKUP NOT WORKING! INDEX/MATCH STILL WORKING!
try this formula
The formula in cells
B2: =INDEX(E:E,MATCH(A2,F:F,0))
C2: =INDEX(G:G,MATCH(A2,F:F,0))
MATCH(A2,F:F,0) is finding Cell A2 in column F (0 means it will find
exact match) and will return the first row number when it would find that
INDEX(E:E,MATCH(A2,F:F,0)) will return contents of column E where row number is returned by the Match formula
I have the following formula to make a unique list from column plant in table 15:
{=IFERROR(INDEX(Tabel15[Plant];MATCH(0;COUNTIF(Analyses!$Q$2:$Q2;Tabel15[Plant]);0));"")}
This formula is working, but when there is just 1 value in column plant the formula gives a value of 0. This is wrong because it should return the value.
Does anyone know how I can adapt this formula to make it work?
I wanted to change it to this:
{=IF(COUNTA(Tabel15[plant])>0;INDEX(Tabel15[Plant];MATCH(0;COUNTIF(Analyses!$Q$2:$Q2;Tabel15[Plant]);0));Kopie - datablad$G$2)}
But it doesn't work either.
Good mock example. Try and see if this works:
The formula counts the unique cells against another list. The unique list expects to take the first row, no matter what. It also expects you to have more than one value in your duplicate list. If it doesn't you can't compare since it expect duplicates and it throws an error, #N/A. This is mask as blank cell since it's wrapped in IFERROR:
"Unique formula" = IFERROR(INDEX(Tabel15[Plant],MATCH(0,COUNTIF($Q$1:Q2,Tabel15[Plant]), 0)),"")
To solve this we check how many values it exist in our duplicate list:
=IF(COUNTA(Tabel15[Plant])>1,... "Unique formula" ... ,Tabel15[Plant]) //***//
This will give us this result.
Then you probably don't want duplicates...
So we need to check if previous rows contain any of the values the formula would return.
The VLOOKUP formula do that for us, and as lookup value we use the formula above //***// and lookup range will be our current column: $Q$1:Q2. NOTICE this is a dynamic range so Q2 is relative reference (no $).
=IF(ISERROR(VLOOKUP(IF(COUNTA(Tabel15[Plant])>1,IFERROR(INDEX(Tabel15[Plant],MATCH(0,COUNTIF($Q$1:Q2,Tabel15[Plant]), 0)),""),Tabel15[Plant]),$Q$1:Q2,1,FALSE))
So the Final result we need to apply is this in Cell Q3:
=IF(ISERROR(VLOOKUP(IF(COUNTA(Tabel15[Plant])>1,IFERROR(INDEX(Tabel15[Plant],MATCH(0,COUNTIF(Analyses!$Q$1:Q2,Tabel15[Plant]), 0)),""),Tabel15[Plant]),Analyses!$Q$1:Q2,1,FALSE)),IF(COUNTA(Tabel15[Plant])>1,IFERROR(INDEX(Tabel15[Plant],MATCH(0,COUNTIF(Analyses!$Q$1:Q2,Tabel15[Plant]), 0)),""),Tabel15[Plant]),"")
The macro error can be ignored by:
If Not IsError(Sheets("Hulpblad").Range("B6").Value) Then
t = Sheets("Hulpblad").Range("B6").Value
'Code...
End If
there is no problem in your formula, it is just telling that there are blanks in the range, 0 means blank. the formula is treating the blank as a value and also considering it in the unique value calculations.
If you want to remove 0 you can just insert an if over your formula to remove it. like
=if(formula = 0, "", formula)
or in orignal form
=IF( (IFERROR(INDEX(Tabel15[Plant],MATCH(0,COUNTIF(Analyses!$Q$2:$Q2,Tabel15[Plant]),0)),""))=0,"",IFERROR(INDEX(Tabel15[Plant],MATCH(0,COUNTIF(Analyses!$Q$2:$Q2,Tabel15[Plant]),0)),""))
or go in the cell formatting and change the format to display 0 as a dash.
sometimes blank is also used as error checking, you can apply such formulae as well to check how many are blank, maybe that would someday be used to check any data entry problems.
I know that I can use [#col1] to refer to the cell within col1 that is on the same row as the formula. But is there a way to refer to the cell that is on the row above? Maybe something like: [#col1 - 1] (hypothetical)
Try
=INDEX([col2],ROW()-2)
In the first table row, the formula will return a 'wrong' value, i.e. the value of the same row, but in the next row it will show correctly.
If you want to calculate a running total, you can use something along the lines of
=SUM([#col1],INDEX(C:C,ROW()-1))
Note how the reference for Index is the whole column. Using Sum() will ignore text, so the formula will not return an error when the column title is involved.
Not sure there is a built in way, but you can always index match. Something like
=INDEX(A:A, MATCH([#Col1],A:A, 0)-1)
Change the A:A to whatever column you want to reference and -1 for one row up, -2 for two rows up, and so on.
This gives you distance of the row you're on from the header row, and handles the first row with no problem.
=(ROW() - ROW([#Headers])-1)
Easy to adapt for use with OFFSET or INDEX to give you the previous row.
I've searched for an answer for this for awhile now but haven't had any luck. It's a bit difficult to put into words, so please let me know if anything's unclear.
What I want is a way to perform conditional statements on two columns. When both conditions are true, I want to return the value from a third column that is in the same row as where these conditions were met. So if the conditions are true in D5 and C5, I want to return the value from Q5 into the cell with the formula. The conditional statements are easy enough but I haven't figured out the last step yet.
If I use the following formula, I get 1 in the cell with the formula, which is right.
=IF(AND('Stata Output'!D2:D6='Backcheck schedule and results'!C2, 'Stata Output'!C2:C6=1),1,0)
However, replacing 1 in the formula with the range of cells that I want to pull the value from gives me a zero every time, which I know is wrong. For this latter formula I'm using:
=IF(AND('Stata Output'!D2:D6='Backcheck schedule and results'!C2, 'Stata Output'!C2:C6=1),'Stata Output'!Q2:Q5,0)
Any ideas on where I'm messing up?
Thanks!
Give this a shot - I'm sure there is a simpler way but it seems to get the job done (make sure to enter as an array formula with Control+Shift+Enter):
=INDEX('Stata Output'!$D$2:$Q$6,MATCH(1,(--('Stata Output'!$C$2:$C$6=1)*--('Stata Output'!$D$2:$D$6="Backcheck schedule and results")),0),14)
What this does is take your entire table as the range (first argument to INDEX, then uses MATCH to find the row where both of your conditions are met (in this case, column C must be 1 and the corresponding value in column D must be Backcheck schedule and results). You then search the resulting array for 1 (which indicates the match) and return column 14 (which represents column Q in our table). You can continue to add filters inside the MATCH() function as needed.
Note that this will match only the first 'hit'.
Looks like AND isn't working correctly in array formulas, so I would use this:
=IF(('Stata Output'!D2:D6='Backcheck schedule and results'!C2)*('Stata Output'!C2:C6=1)=1,'Stata Output'!Q2:Q5,0)
This will give you a new results column, that will be filled from the Q2:Q6 column for every matching row.
To use it, you should select all of the results column, input the formula and then use CTRL+SHIFT+ENTER.
Just make sure to use use ranges of the same size.
Try the following formula:
=LOOKUP(2,1/('Stata Output'!D2:D6='Backcheck schedule and results'!C2)/('Stata Output'!C2:C6=1),'Stata Output'!Q2:Q5)
If there is more than one row where both conditions are satisfied, this formula will return the col Q value from the last of those.