Excel Index Match Formula last change - excel

I've got a column U and a column L.
What I need to get is the value from column L when searched in column U.
Column L Column U
516 11
123 11
74 5
46 11
748 21
156 11
189 21
187 21
For example:
I want to search 21 in column U but I need to find the first value from the last change
(the number stays the same further in the column).
So if I want the value belonging to 21 I need to get 189.
I tried it with (thanks to Scott Craner):
=INDEX($L:$L,AGGREGATE(14,6,ROW($U$10:$U$500)/($U$10:$U$500=D2),1))
But this gets me the last 21 value so 187 as answer.
Does anybody know how to solve this?

You need to find the last row in column U with the value from D2 where the row immediately above it is not the same value.
=INDEX(L:L, AGGREGATE(14,6,ROW(U$10:U$500)/((U$10:U$500=D2)*(U$9:U$499<>D2)),1))
Now change U15 to be another 21. The result becomes,
For a dynamic number of values in columns L and U (starting in row 10), use,
=INDEX(L:L, AGGREGATE(14,6,ROW(U$10:INDEX(U:U, MATCH(1E+99, U:U)))/((U$10:INDEX(U:U, MATCH(1E+99, U:U))=D2)*(U$9:INDEX(U:U, MATCH(1E+99, U:U)-1)<>D2)),1))

If I understand you correctly, I believe this accomplishes the task:
=INDEX($L:$L,MATCH(INDEX($L:$L,AGGREGATE(14,6,ROW($U$9:INDIRECT("$U$"&MATCH(INDEX($L:$L,AGGREGATE(14,6,ROW($U$10:$U$500)/($U$10:$U$500=D2),1)),$L:$L,0)))/($U$9:INDIRECT("$U$"&MATCH(INDEX($L:$L,AGGREGATE(14,6,ROW($U$10:$U$500)/($U$10:$U$500=D2),1)),$L:$L,0))<>D2),1)),$L:$L,0)+1)
It builds on Scott's concept, and finds the 187, then limits the search arrays to the row where it finds 187, and finds the last row that does not have the number you are searching for (21). Then it indexes the first row after that, which will be the first match in the last series.

Related

Excel: How to not count a particular cell on condition?

I need to calculate a column having many cells but I want to not calculate particular cells on condition. For example:
Scenario:
Sr No Marks
1 46
2 33
3 44
4 32
5 11
6 99
7 27
8 98
I want to get the sum of marks but only those cells should be added whom marks are more than 50. What formula should use?
We can use SUMIF here:
=SUMIF(B2:B9, ">50")
This assumes that your Marks column is in column B, and that the first data point is on the second row.
Edit:
If you want to take the average value of marks, where the mark is over 50, then we can also use COUNTIF:
=SUMIF(B2:B9, ">50") / COUNTIF(B2:B9, ">50")

Excel Hlookup function returning the first character in table

I am using Hlookup to find in a row where the value is "A", and then subsequently take a binary value in the same column and use this as the selected cells value.
I am only using the formula bar for this part. The cells formula is:
"=HLOOKUP("A",A13:Z19,1)"
Row 13: SNPHUATVBKWJZYMQGXFCROEILD (Each character is assigned to an individual cell).
In row 19, each cell is taken up by 5 binary digits, so to keep things tidy I will write the decimal numbers:
10 3 2 20 18 6 24 2 12 21 30 4 6 26 19 22 9 13 5 24 0 31 12 15 24 9
The issue is that, while my formula should return 6, as that is the corresponding value within the same column as the letter "A", it returns 9, which is the first cell on the top right of the search criteria table.
Also worth noting is that if I post in a different cell a similar formula but perhaps change the search criteria to a different character such as "H", then the same error will occur, returning a 9.
Thank you so much in advance!

How to use index and match concept to retrieve values from 2nd row and 3rd column or 1st row and 4th column and so on

Jan Feb Mar Apr May
1 10 110 101 11 90
2 20 111 102 12 91
3 30 112 103 13 92
4 40 113 104 14 93
5 50 114 105 15 94
How to use index and match concept to retrieve values from 2nd row and 3rd column or 1st row and 4th column and so on
If you wanted to match cell $B$2 (Row 2, Column "February") you could use the following formula:
INDEX(B1:B5, MATCH(91, E1:E5, 0))
This would give the value 111, which is the value of $B$2
The INDEX function in Excel takes a range (B1:B5) and an index into that range, and returns the value. In an INDEX MATCH, the index used is actually a call to the MATCH function. Here, I obtained an index of 2 when MATCHing the value 91 in the range E1:E5.
In English you might read this call as saying "Find the value in the range B1 to B5 whose index is the same as the value 91 in the range E1 to E5."
If the months are in B1:F1, row labels in A2:A6 and main body of the table in B2:F6 then you can get the value at the intersection of the nth row and kth column of B2:F6 using this formula
=INDEX(B2:F6,n,k)
As per Tim's answer you can derive the n and k values using MATCH functions based on the values in the column headers and row labels, e.g. matching "Apr" and 4 will give you the value at the intersection, i.e. 14
and the formula would look like this
=INDEX(B2:F6,MATCH(4,A2:A6,0),MATCH("feb",B1:F1,0))
see here for more

Index/Match values from a column using a grid of a different length (Excel 2010)

I am trying to index match values from a long column to a grid of a different length. It looks like this
Word Number Column X Column Y Column Z
This 55 55 33 12
is 62 62 42 18
The 78 78 31 24
42
31
12
18
24
33
The grid (Column X,Y,Z) contains all the values from the Number Column. What I am trying to do is basically index the "Word" column, using a value from the "Number" Column, and looking it up in the value array of X Y Z.
Example (because this is confusing):
Input the Value 33 from the Number column, look for the value in the columns XYZ, and then return the Word "This".
Input the Value 18 from the number column, look for the value in columns XYZ, return the word "is"
etc...
Any help would be very much appreciated!
there is a quicker way and shorter formula to do this:
=IFERROR(INDEX(A:A,IFERROR(MATCH(B2,C:C,0),IFERROR(MATCH(B2,D:D,0),MATCH(B2,E:E,0))),1),"not found")
paste that into, any column really, into row 2 and drag down, it will return the words you require, if value not found it will return "not found"
Here is your spreadsheet starting at cell A1 (without your headers):
A B C D E
1 This 55 55 33 12
2 is 62 62 42 18
3 The 78 45 31 24
4 42
5 31
6 12
7 18
8 24
9 33
10
11 Input: 24
12 Output: The
Copy this into cell C10, and drag the formula across to cell E10:
=IF(ISERROR(IF(ISERROR(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))),"",INDIRECT(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))))),"",IF(ISERROR(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))),"",INDIRECT(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0))))))
Copy this to the "output" cell B12 and use cell B11 as your "input":
=CONCATENATE(C10,D10,E10)
VIOLA!!! You're done!
Proof:
The MATCH() function will look for your value in an array (the range). If it finds it, it returns the index of that array (indexed at 1), otherwise it throws an error. Be sure to set the 3rd argument to "0" so that it only looks for EXACT matches.
Paste this into C14:
=MATCH($B$11,C1:C3,0)
Next, we check if the MATCH() function did indeed throw an error. Paste this into C15:
=IF(ISERROR(C14),"",C14)
Now we have the row number of our matched value, so we will use the CONCATENATE() function to join it to our "word column", A, for use in the next step. Paste this into C16:
=CONCATENATE("A",C15)
Using that string from above, use the INDIRECT() function to turn it into an actual cell reference. Paste this into C17:
=INDIRECT(C16)
And finally, check if a legitimate cell reference was created. If so, return the word, otherwise return "". Paste this into C18:
=IF(ISERROR(C17),"",C17)
Lastly, drag the formulas from C14:C18 to E14:E18, and concatenate the results. The cells in row 18 should match the cells in row 10.
Hope this helps :)

Excel VLOOKUP or INDEX MATCH

Lets say I have 3 columns of data
AMOUNT(A) AMOUNT(B) INVOICE(C)
55 49 4541
47 47 1515
42 47 4478
86 12 9993
12 100 1224
5 44 1452
100 4287
99 4444
What I need to check to see if the value in column A matches a value in column B. If there is a match, it will return the value from column C in column D. Now this is easy with a VLOOKUP however I am dealing with 700+ lines and there are multiple amounts that match. INDEX(MATCH) could work but it only returns one value. Is this a VB only problem?
I.E Value 47 exists in column B twice so therefore column D would return both invoice numbers (1515 - 4478)
In VBA, the problem would be trivial as you have already correctly described the logic with the problem statement itself.
Using Excel functionality only, without VBA is the interesting problem. You need to do the following steps to achieve an output that looks like this...
The steps are as follows:
Pivot Table: Make a pivot-table from the Columns (B) and (C) with Rows Fields as (B) and (C) and the minimum of AMOUNT(B) as the Value field. (See Figure below)
Helper Columns: Make a column on the side of the pivot table, say (Q) which is simply equal to everything in column (P)
Contd ... : In column (R) (which unfortunately happens to be in the sheet's column Q, sorry for the confusion there), as shown, for cell Q20 for e.g. put in the formula
=IF(P21=P20,Q21&","&M20,M20)
That will result in the creation of something like the table below:
Table:
(P) (Q)
12 9993
44 1452
47 4478,1515
47 4478
49 4541
99 4444
100 4287,1224
100 4287
Now the hard work is done. All you need to do is to lookup using VLOOKUP key-value pairs from this helper table (P)(Q)
- It will be very fast because the pivot table always keeps it sorted and hence an exact LOOKUP is not necessary.
- Screenshots are shown below for the Pivot table as well as for the final VLOOKUP formula
Pivot Table and Helper Table:
Final Formula:
so I'm using the Countif to see if there are dups based on column A.
In the D column type, =IF(COUNTIF($A$2:$A$9,B2)>0,C2,"")

Resources