So, I'm using an Index + Match formula to return an image on a specific cell, but I don't want it to return a duplicate from a previous use of the formula. I realize how unlikely this is with another INDEX + MATCH, as MATCH only returns a position so I can't realistically exclude the previous result there.
Example formula: =INDEX(T2:U5,MATCH(B3:B10,T2:T5,0),2)
Column T includes values to match the B column with, then it returns an image from the U column.
I want to do this twice, but exclude the first result the second time around. I'm fairly new to all these functions so I have no idea where to begin. Does anybody have any suggestions?
I have since found a resolution to my problem. By first separating my target cells from the column with an index filter, then running match filter over those separated cells.
Related
What I'm trying to do is find the name of the person who is ranked number 1 in the table shown below. I have tried =LOOKUP and =VLOOKUP but I get an error saying that a result can't be found, even though it's obviously there. I assume that I'm either using the wrong function or just not using it right.
I tried =VLOOKUP(1;D2:H19;1) and =LOOKUP(1;D2:H19;1) but neither seems to work.
Answer
The following formula should produce the behaviour you desire:
=INDEX(D2:D,MATCH(1,H2:H,0))
Explanation
=VLOOKUP can only be used to find values to the right of a search key. To find values to the left of a search key, use a combination of =INDEX and =MATCH.
The =MATCH function searches a specified range for a specified value and returns the relative position of the value in that range. In this case, the value to search for is 1, the range to search through is H2:H, and the 0 at the end specifies that the range is not sorted in any way.
The =INDEX function returns the contents of a cell within a range having a specified row and column offset. In this case, the range is D2:D, and the row is whichever row is returned by =MATCH. =INDEX could take a third argument if it was desired to specify a row offset as well, but that is not necessary here.
Functions used:
=INDEX
=MATCH
You sort your ascending order based on rank then return your desired data using INDEX() function. Try-
=INDEX(SORT(D2:H500,5,1),1,1)
=vlookup(1,{H2:H19, D2:D19},2)
Since vlookup only searches the 1st column of the input range, to use it, you need to flip the columns by composing a local array: {H2:H19, D2:D19}.
{} means concatenation. , in it means horizontal concatenation. With that, the rank column is now the 1st column in the input of vlookup and now vlookup works.
With our local array, the 2nd column are the names and therefore index should be 2.
Also note the use of comma to separate function inputs.
your VLOOKUP formula should look like:
=VLOOKUP(1, {H2:H19, D2:D19}, 2, 0)
also try just:
=FILTER(D:D; H:H=1)
or:
=SORTN(D:D; 1; 1; H:H; 1)
You can use query (usefull in case of ex aequo)
=query(D2:H,"select D where H=1",0)
A user pastes in a value to see if there is a full or partial match. I need to do a vlookup and keep removing characters until there is a match. A full match of something like test1.test2.test3 is no problem because it's a full match to my list. But if someone pastes in something like test1.test2.test3.test4, I need to remove a character one at a time from the end until there is a match. So in this example, it would match test1.test2.test3 and return that result.
Conceptually I see this as a for loop that counts the characters using len, using left to remove the number of characters from the end based on the current iteration, and doing vlookups until returning the value when true. But I'm not sure how to do this in Google Sheets.
This formula will give you the matching value that was found in the data(i.e. test1.test2.test3)
=FILTER([column_with_data], REGEXMATCH([cell_with_pasted_value_to_look], [column_with_data]))
This formula will give you the matching data and the cell reference where it was found (i.e. test1.test2.test3 # $A$4)
=FILTER([column_with_data], REGEXMATCH([cell_with_pasted_value_to_look], [column_with_data]))&" # "&CELL("address",INDEX([column_with_data],MATCH(FILTER([column_with_data], REGEXMATCH([cell_with_pasted_value_to_look], [column_with_data])),[column_with_data],0),1))
Simply copy & paste any of the above formulas next to the cell where users paste a value to look. Then, replace the two references in the square brackets [ ] with the proper coordinates in your sheet:
replace [column_with_data] with the coordinates of the column containing all the stored data (i.e. A1:A)
replace [cell_with_pasted_value_to_look] with the absolute ($col$row)coordinates of the cell where users paste the value to look (i.e. $B$1)
Would it be a problem to download the data from Google sheets, transform the file type to use the for loop in another software, and re-upload? I think your idea for a for loop would work.
It might be quicker if this is a long term project, but not so great if the client is continually monitoring/uploading.
My table contains 2 sheets with a different number of columns. I want to add a column that will display true or false (or any other 2 opposite values ) for each row depending on whether this row satisfies 2 criteria which are: sheet1!col1=sheet2!col1 and sheet1!col2=sheet2!col2.
You'll find an illustration below.
I've tried using
ARRAYFORMULA(VLOOKUP(A1&B1, {Sheet1!A1:A4&Sheet1!B1:B4,Sheet1!C1}, 3))
but I get an error message
vlookup evaluates to an out of bound range
So I wanted to try
QUERY({Sheet1!A1:B4,A1:B5}, "Select C where ")
but I couldn't figure out how to write the condition where (sheet1)col1=(sheet2)col1 & (sheet1)col2=(sheet2)col2 and I also don't know if I can work with tables of different dimensions. I finally tried
=MATCH(A1&B1,{Sheet1!A1:A&Sheet1!B1:B})
but it always returns 1.
Any idea please?
Sheet 1
Sheet 2
Your first formula is almost right. You are getting the error message because there is only one column in the curly brackets so you have to change it to
=ArrayFormula(vlookup(A1&B1,{Sheet2!A:A&Sheet2!B:B},1,false))
and add the 'false' to make sure it only does exact matches.
To make the query work you need the right syntax to access cells in the current sheet:
=query(Sheet2!A:B," select A,B where A='"&A1&"' and B='"&B1&"'")
To make the match work, you need to enter it as an array formula and add a zero to specify exact match:
=ArrayFormula(MATCH(A1&B1,{Sheet2!A:A&Sheet2!B:B},0))
However I would take flak from my colleagues if I didn't point out that there is an issue with the vlookup and match as shown above - toto&moto would match with not just toto&moto, but also with tot&omoto etc. The way round this is to add a separator character e.g.
=ArrayFormula(vlookup(A1&"|"&B1,{Sheet2!A:A&"|"&Sheet2!B:B},1,false))
=ArrayFormula(MATCH(A1&"|"&B1,{Sheet2!A:A&"|"&Sheet2!B:B},0))
These still need some tidying up if they are to report Yes and No, and also not to give false positive on blank rows - also the vlookup and match can be written as self-expanding array formulas - but that is the short answer to the question.
I have two sets of data in columns A and B. I would like to pick the maximum value from column A which is also less than the value in the corresponding row in column B. I think I ought to be able to do this with the MAXIFS function but all the examples I can find compare against static values. I tried these options
=MAXIFS(A1:A10, B1:B10, "<")
=MAXIFS(A1:A10, B1:B10, A&"<"&B)
but neither of them worked as expected. In the first case, it is always 0 suggesting the condition is never met, in the second it gives an error.
I know that I could do this by creating a separate region of cells which first filter out the data that doesn't match the conditional and then simply pick the max from what remains but I'd rather do it in a single cell if possible.
Is there a syntax for this comparison and, if so, what is it?
To the best of my knowledge there isn't a way of getting it to work with MAXIFS.
You can write this
=maxifs(A:A,A:A,"<"&B:B)
and it will accept it, but it just uses the first value in column B and doesn't do a side-by-side comparison.
So you have to do it another way e.g. with a combination of Max and If:
=ArrayFormula(max(if(A:A<B:B,A:A)))
or you can use max with a filter or query:
=max(filter(A:A,A:A<B:B))
=max(query(A:B,"select A where A<B"))
=ARRAY_CONSTRAIN(ARRAYFORMULA(
IF(LEN(INDIRECT(ADDRESS(ROW(), COLUMN(B:B))))>0,
IF(INDIRECT(ADDRESS(ROW(), COLUMN(B:B)))<MAX($A$1:$A),
MAX($A$1:$A), LARGE(UNIQUE($A$1:$A), 2)), )), 1, 1)
I am trying to find a closest absolute value with index match. I looked at several other posts like here but what i am trying to do is a bit different as i want to add multiple search criterias.
As you can see , I am trying to get the absolute closest time for a specific person.
I am using the formula =index(C2:C21,match(F4,B2:B21,-1),match(E4,A2:A21,0)) and I had to copy column B in column C to make my 1st match work. The result is shown in G4. Unfortunately I am struggling to get the correct result.
Effectively I would like use the formula that was posted in the previous post (see link at the top) =INDEX(E2:E21,MATCH(TRUE,INDEX(ABS(D1:D21-I4)=MIN(INDEX(ABS(D2:D21-I4),,)),,),0))
with with a search criteria (the name of the person).
Any help would be much appreciated
Thank you
Thanks #avram
I still end up with some cases where the formula does not work. See below. in G6 and G7 i should get 10:25. (You can ignore column A)
Try this formula in G4,
=index(C$2:C$21, match(min(index(abs(index(C$2:C$21+(B$2:B$21<>E4)*1E+99, , )-F4), , )), if(B$2:B$21=E4, abs(C$2:C$21-F4), 1E+99), 0))
This will work in either google-sheets as a standard (non-array/non-CSE) formula or excel as an array (CSE) formula.
If anyone else wants to tackle this problem with a more elegant formula, you can copy the sample data from this publicly shared google-sheet.
Index match find closest value with multiple search criteria
Perhaps this may exempt a fourth person from retyping the same tired data that the op delivered in image(s).
A very simple approach using a "helper" column with data like:
We want the closest absolute match for larry to 10:15 AM. We enter larry in E1 and 10:15 AM in F1
Then in D2 we enter:
=IF(A2=$E$1,ABS(B2-$F$1),"")
and copy downward. (this is the absolute difference for larry) Finally in E2:
=INDEX(B:B,MATCH(MIN(D:D),D:D,0))
With bigger tables having more columns, it is very easy to add additional criteria if needed.
This answer uses Array Formulas which must be entered using CTRL+SHIFT+ENTER. It's kind of complicated, so I'll do my best to explain and will revise if necessary. Here's a screenshot:
Here is the formula in its raw form; names are entered in column A, Times in Column B.
=INDEX(B1:B7,MATCH(MIN(IF(A1:A7=D2,ABS(E2-B1:B7),"")),IF(A1:A7=D2,ABS(E2-B1:B7),"")))
As you might suspect, it uses INDEX/MATCH to get the job done, but the key is using an IF statement to generate both the search criteria and the array that the MATCH function searches within. Let's break it down.
Sec 1, Match Search Array
IF(A1:A7=D2,ABS(E2-B1:B7),"")
This creates the Search array for the match function. If the name in D2 (our criteria) is equal to the name in the search array, it return the absolute value of the difference between the criteria time and the time in the array we're searching. Otherwise it returns a blank value. Do not use 0 for this as it will skew the match result.
Sec 2, Match Search Criteria
MIN(IF(A1:A7=D2,ABS(E2-B1:B7),""))
This tells us the smallest value in the above array. We use this value as the search criteria in the MATCH function.
Sec 3, putting 1 & 2 Together
MATCH(MIN(IF(A1:A7=D2,ABS(E2-B1:B7),"")),IF(A1:A7=D2,ABS(E2-B1:B7),"")) This searches for the smallest abs difference defined in Section 2 within the array created in Section 1 and returns the row number.
Sec 4, Indexing the times
=INDEX(B1:B7,MATCH(MIN(IF(A1:A7=D2,ABS(E2-B1:B7),"")),IF(A1:A7=D2,ABS(E2-B1:B7),"")))
This returns the time value from column B in whatever row is identified by the Match function above.
Hopefully this all makes sense. Remember to enter it as an array formula.