I am using Formula as:
=INDEX(B1:G1,H3)
Its not working. even tough similar posts are present I could not find the issue with this.
I am actually doing a max of all the Row entities like:
=MAX(B2:G2)
and doing
=INDEX(B1:G1,H2)
It works for first row and not for the other
INDEX wants the relative position not the value. You need to add a MATCH:
=INDEX($B$1:$G$1,MATCH(H2,B2:G2,0))
The Match will return the relative position of the match.
Index is using H3 to determine the column to return. That is why Row1 is functioning. It is finding column 6 (between B1:G1) and returning the result. It is only happenstance that it is the correct answer. If you were to substitute 5 into cell H2 it would likewise return Column5. In the other examples shown, the max function is returning a column index which is beyond what is in the array (B1:G1 is 6 columns long).
To correct, pair Index with the Match function. Match will search the array (B2:G2; B3:G3; etc.) and return the column number of the matching column, then pass that on to the Index function to return the proper result.
Your final formula will look like this:
=INDEX($B$1:$G$1, MATCH(H2, B2:G2, 0))
Related
I was wondering if anyone could enlighten me on a way to condense/shorten this formula:
=IF(ISNUMBER(SEARCH("Kirkintilloch",B2)),"BRN01",IF(ISNUMBER(SEARCH("Tweacher",B2)),"BRN01",IF(ISNUMBER(SEARCH("Lenzie",B2)),"BRN01",IF(ISNUMBER(SEARCH("Bishopbrigg",B2)),"BRN03",IF(ISNUMBER(SEARCH("Torrance",B2)),"BRN03",IF(ISNUMBER(SEARCH("Bearsden",B2)),"BRN04",IF(ISNUMBER(SEARCH("Milngavie",B2)),"BRN04")))))))
Column B will contain an address which will be from one of these seven towns.
The reason I didn't do an IF then Lookup was that the result I want to return is not unique, I.e. Kirkintilloch & Torrance both need to return a result of BRN01.
If it's not possible to simplify this then no worries. It would just save me a lot of work in a larger piece of work with many more possible outcomes.
This is an array formula - confirm it with Ctrl+Shift+Enter while still in the formula bar:
=INDEX(Towns,SMALL(IF(ISNUMBER(SEARCH(INDEX(Towns,0,2),B2)),INDEX(Towns,0,1)),1),3)
Breaking this down:
First you need to create a named range (I called mine "Towns") that contains the array of an index, the town name and the desired return "BRN**" (you could make this a simple range and just reference that but I entered the actual array by selecting the range in formula, highlighting it and using F9 to calculate)
Now that you have this array, I use Index providing 0 for the row argument to return all rows so that I can equate against just a single column at a time.
IF(ISNUMBER(SEARCH(INDEX(Towns,0,2),B2)),INDEX(Towns,0,1))
As this is an array formula, each row is assessed individually and the results (first column when a match is found - index of the array) returned as an array, like so: {FALSE;FALSE;3;FALSE;FALSE;FALSE;FALSE}
I then use SMALL() to catch the lowest number or the first match to feed another index for the third column.
I know how to use index and match formulas to get the value or location of a matching cell. But what I don't know how to do is get that information when the cell I'm looking for isn't going to be the first match.
Take the image below for example. I want to get the location of the cell that says "Successful Deliveries". In this example there's a cell that matches that in rows 11 and 30. These locations can vary in the future so I need a formula that's smart enough to handle that.
How would I get the location of the second instance of "Successful Deliveries"? I figured I could use the "Combination 2 Stats" value from row 24 as a starting point.
I tried using this formula:
=MATCH("Successful Deliveries:",A24:A1000,0)
But it returns a row number of 7 which is just relative to the A24 cell I started my match at.
My end goal here is to get the value from the cell directly to the right of the second match of "Successful Deliveries".
In your formula, with no further intelligence, you can simply add 23 to adjust 7 to the result:
=MATCH("Successful Deliveries:",A24:A1000,0) + 23
You know that 23 is the number to add because you started your search on row 24.
The full answer is here:
https://exceljet.net/formula/get-nth-match-with-index-match
You use this formula:
=INDEX(B1:B100,SMALL(if(A1:A100 = "Successful Deliveries:",ROW(A1:A100) - ROW(INDEX(A1:A100,1,1))+1),2))
...where 2 is the instance you want.
Make sure to finish typing the formula by hitting ctrl-shift-enter. (You know you did this right because the formula gets curly brackets {})
HOW IT WORKS
Normally, we use INDEX / MATCH to find a value. The Index function gives you the nth value in a range, and the Match function determines which "n" is a match for our criteria.
Here we use INDEX the same way, but we need more intelligence to find that "n", since it's the second one that matches the criteria. That's where SMALL comes in. The Small function "gets the nth smallest value in an array". So we give Small the number of the desired instance (2 in this case) and we give it an array of blanks and the rows numbers of the rows we like.
We obtained the array of blanks and row numbers using the If function, asking it to check for our criterion (="Successful...") and making it return the row number where the criterion passes (=Row(A1:A100)). By using the If function as an array function (by giving it arrays and using ctrl-shift-enter) it can deliver a whole list of values.
Our final value is just one number because the Small function used the array from the IF to return just one thing: the second-smallest row we gave to it.
I'm trying to do what should be a simple enough task: find the index of the last cell in an array that matches a certain value.
I am using a MATCH-INDEX function combination that is giving me incorrect, inconsistent results. I can't figure out the problem.
In this example I'm using an array with values of 1 or -1 and trying to find the index of the last 1 in the array.
My understanding is (and using the Evaluate Formula tool confirms), INDEX(A1:F1=1,0) should return an array of
{FALSE,TRUE,FALSE,TRUE,FALSE,FALSE}
Why does the MATCH(TRUE,...) not give a result of 4 when it is fed this index array? MATCH works backwards in the array and should return the index of the last match, which is the TRUE value in the 4th position.
But here this code is giving a result of 6.
To make matters worse, if I use the same code but change around the array fed into INDEX, the results are inconsistent. When I'm changing array values to 1 or -1, sometimes the formula result changes and sometimes it doesn't, and I can't figure out why.
Below, changing only the 3rd array value changes the result of the formula from 4 to 6. WHAT IS GOING ON?!
It seems that match only finds first, but not last.
But I have a possible solution, I would do it the following way:
expect: your values are between H4 AND H27, the value you look for is "39"
1: find the rownum for all matching cells
I4 --> I27: IF(H4 = 39; ROW(H4); -1)
2: find the max rownum in I4 --> I27
MAX(....)
3: subtract the rownum of first cell (zero- based index)
MAX(....) - ROW(H4)
4: to get it in only one cell put into a Matrix function (CONTROL SHIFT ENTER makes CURLY BRACKETS)
{=MAX(IF($H$4:$H$27=39;ROW(H4:H27);-1))-ROW(H4)}
sounds strange, but works :)
Index doesn't return an Array, but a number, as the name tells you, the "INDEX" of the element, which fulfills your question. With the last Parameter you can decide, whether it has to be exact or could be the next smaller or next bigger value (last both options will only work with sorted Input)
You can solve your question either in more then one step as written in my last answer or with matrix functions, in your special case (now with columns instead of rows):
{=MAX(IF(A1:F1=1;COL(A1:F1);-1))}
I have a data source in the format as the one below. In reality, that would contain few thousand rows.
I need to use something like INDEX-MATCH-MATCH in order to be able to get the "Status" for each "Content" item for each UserID.
The final result should look like this. The first two columns are not dynamic.
The INDEX formula goes to C and D.
I am using the following sequence to try and write the formula, but I don't seem to understand where the problem is.
=INDEX(Sheet1!A:K, [Vertical Position], [Horizontal Position])
look up the user with ID xxx:
=INDEX(Sheet1!A:K, MATCH(A2, Sheet1!A:K,0), [Horizontal Position])
look up the status for eLearn1.
=INDEX(Sheet1!A:K, MATCH(A2, Sheet1!A:K,0), MATCH("Status", Sheet1!A:K,0))
What am I doing wrong?
The question is not clear, but I think you are trying to do a LOOKUP based on the values of two columns. So for a particular value of Column A (UserID) and Column B (Content) you need to return Column H (Status).
This can be done using an array formula to return the row number of the matching line which can be fed into INDEX. Note, that this will only work as long as Columns A&B only have unique pairings.
I have set up some sample data:
Columns A-C are my source data. Cells G2:H4 are the lookup.
The formula is:
=INDEX($C$1:$C$7, SUM(($A$1:$A$7=$F2)* ($B$1:$B$7=G$1)*ROW($C$1:$C$7)))
This needs to be entered as an array formula by pressing CTRL-ALT-ENTER.
The formula works by matching the value you are searching for in both arrays and multiplying out the results. This should give you a result array consisting of all False with one True indicating the matched row. This is then multiplied against the row number to return the correct row to the INDEX formula.
I have the data table below, and I want that given a value 'x' look in 'A' and get the lower value in 'B'.
For instance 10.000 should return 0, 38.000 should return 7,8 and 900.000 should return 20. In my locale '.' means thousand separator and ',' is for decimals.
If possible I would like a formula which works in excel and gdocs. Thanks.
A B
0 0
37.500,01 7,8
45.000,01 9,1
58.345,62 11,4
120.206,02 13,6
208.075,91 15,7
295.242,83 17,2
382.409,77 18,2
600.000,01 20
I don't know about gdocs but in excel try the following.
=vlookup(value ; $A$1:$B$9 ; 2 ; 1)
where value is the value you are searching for.
The only prerequisite is that column A must be sorted in ascending order, as you have in your example.
You can use LOOKUP function, assuming lookup value in C2 use this formula in D2
=LOOKUP(C2,A$1:B$9)
The following would work for your needs:
=INDEX(B:B,MATCH(38,A:A,1),1)
Where 38 is the value we are looking up. Match will look in A:A and return the row where the value is less than 38 (because the third parameter of the match() formula is 1).
The Index will return the row in B:B that Match() just outputted.
If you search for 900,000 you're hoping to return the value from 600,000.01, because that's the last value it is higher than.
You can do this with an array formula, but I prefer to make Index do that work for me. As such, I present INDEX/MATCH/INDEX:
First, sort your data in A Largest to Smallest.
=INDEX($B$1:$B$9,MATCH(TRUE,INDEX(900000>$A$1:$A$9,0),0))
You can change 900,000 to whichever number you're looking for, or reference a cell with the value in it.
The second INDEX, the one nested in there, is examining each cell in Col A to determine if your target value is greater than them. It creates an array of TRUE's and FALSE's.
Next, you use MATCH to find the first TRUE in that array you created. That's the position of the first cell that your target is greater than (this is why we sort largest to smallest).
Once we know how far down the list it is, we use the first INDEX to look that far down Col B and grab the info you're looking for!
Play around with it, it makes sense once you think your way through it :) Good luck!