I'm trying to use the approximate match function of vlookup to find a value in an array, that can be of different length. I just dragged the lookup array as far down as possible in order to assure that all data is selected, however, the approximate match option will then always select the last value in the array. Is there a way of feeding vlookup the correct lookup array in order to extract the correct value? Regards
Create a dynamic range name and feed that into the Vlookup. For example, if your lookup table starts in A1 and has numeric data, define a name called TheRange with the formula
=Sheet1!$A$1:Index(Sheet1!$D:$D,match(99^99,Sheet1!$A:$A,1))
This will return a range from A1 to column D down to the last row with a number in column A. When rows are added or removed from the table, the named range will be recalculated automatically and adjust to the new dimensions.
Then can use
=vlookup(YourValue,TheRange,2,1)
Adjust cell addresses to your situation. I take it you are aware that for an approximate match the data must be sorted ascending for the formula to return the correct result. With the 1 or TRUE as the last parameter, the formula will always return a result, but if the table is not sorted on the first column, the result is most likely not correct.
Related
I would like to return the sum of all values that are directly below a look up value "Pre173RB" in a single column.
First I used index and match but this is limited to only finding the first value "8".
=INDEX(B:B,MATCH(E1,B:B,0)+1,1)
I then attempted to incorporate the above formula into the repeating sequence below. The formula returned the first value in the column "30". The desired return is "18".
=INDEX(B:B, SMALL(IF(ISNUMBER(MATCH(E$1,B:B,0)+1), MATCH(ROW(B:B), ROW(B:B)), ""),ROWS(A$1:A1)))
I've attempted to use sumif in the above formula as well but errors return.
Any assistance is appreciated. I am probably complicating the formula.
=SUMIFS(B2:B26,B1:B25,E1)
Note that the sum range is offset one row versus the condition range.
I have a table that I want to export the data to a table that contains a column of names, dates and attendance so that it takes the values from the table
like this picture
You want INDEX and MATCH. See the formula at this Google Sheet, but it will work the same in Excel This is the top of the two examples:
https://docs.google.com/spreadsheets/d/1bvp6-Jb82A-AEOxvnMLzUNxWUSCKt1merc2nfSt3viE/edit?usp=sharing
=INDEX(F10:M13, match(O13, F10:F13, 0), match(P13, F10:M10, 0))
INDEX takes a range, and two numbers, one for the row and one for the column, and returns the value (or reference) at that intersection. You can pass false or null for either one of the numbers and return the entire row or column of the range, or if you are working with a single dimensional array, like a row or a column, you can just pass one number to it.
MATCH takes a value and a range (and an optional lookup type) and returns the index of that value in the range.
So using INDEX with two MATCHes, you can find the row and column of the data you are looking for.
DOCS:
https://support.microsoft.com/en-us/office/index-function-a5dcf0dd-996d-40a4-a822-b56b061328bd
https://support.microsoft.com/en-us/office/match-function-e8dffd45-c762-47d6-bf89-533f4a37673a
It is possible to do this with VLOOKUP, but I find INDEX/MATCH to be more intuitive and more flexible. Here is a VLOOKUP implementation. It is the bottom of the two examples on the demo sheet:
=vlookup(O16, F10:M13, match(P16, F10:M10, 0))
As you can see, you still pass it the data range and use match to get the column, but VLOOKUP will find the row with the lookup value for you, as long as it is in the first column. INDEX/MATCH lacks this limitation, and I find the arguments more logical: INDEX(range, row, column) vs VLOOKUP(lookup value, range, column).
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 have a table with the following header and totals row:
. It has data rows with module names and numbers for the other columns.
I also have this table:
. In the Allocation column each specific segment gets one of: CODE_ZONE, CONST_ZONE or RAM_ZONE.
For each module (row) in SegmentValues I need to make its CODE_ZONE, CONST_ZONE or RAM_ZONE cell the sum of all the segments allocated there, based on the allocation in Segments. I have tried with this formula: =SUMIF(Segments[Allocation], "CODE_ZONE", SegmentValues[#[DIFUNCT]:[SECUID]]), but it only works for the first element. What function should be used in this situation and how?
Try using MMULT function like this:
=MMULT(SegmentValues[#[DIFUNCT]:[SECUID]],(Segments[Allocation]="CODE_ZONE")+0)
MMULT will multiply each value in a single row with the corresponding values in a single column of the same size (and sum the results for a single value). All values need to be numeric so (Segments[Allocation]="CODE_ZONE") returns an array of TRUE/FALSE values and adding 0 converts those to 1/0 values
The SegmentValues range must not contain blanks, but zeroes are OK
I managed to do it using this formula:
=SUMPRODUCT(SegmentValues[#[DIFUNCT]:[SECUID]]*(SegmentValues[[#Headers],[DIFUNCT]:[SECUID]]=Segments[Segments])*(Segments[Allocation]="CODE_ZONE")
It is a SUMPRODUCT with only one array, taken from only one range, but with two conditions:
The header of the cell to be added from SegmentValues matches the segment name in Segments.
The the cell in the Allocation column corresponding to the said Segment cell is CODE_ZONE.
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.