Nested Xlookup First Non-blank Cells - excel

Name Day 1 Day2 Day 3
John 3 2
John 2 1 4
Using a double Xlookup, when I'm searching for John and Day 2, I cannot get the value 1 and I'm trying Index/Xmatch/xmatch to return me 1 but no luck. Any idea to go about it?
###Updated example picture here###
enter image description here
This is my current formula
=XLOOKUP("John",$A$2:$A$3,XLOOKUP("Day 2",$B$1:$D$1,$B$2:$D$3),,2)

Note that your comments show a different case (wildcard search in names) than your question.
The following formula will result in the first found value of the wildcard search for names starting with the search string in F2 and matching the date in F3:
=LET(range,A1:D3,
c,1-COLUMNS(range),
r,1-ROWS(range),
days,TAKE(range,1,c),
names,TAKE(range,r,1),
data,TAKE(range,r,c),
x,FILTER(data,days=F3),
TAKE(
FILTER(x,
(ISNUMBER(XMATCH(F2&"*",names,2)))*
(x<>"")),
1))

You cannot use XLOOKUP two-way exact match, because it returns the first match and you have duplicated values in column Name.
This solution returns the first non blank value from the input data based on the lookup values. In cell H2 put the following formula:
=LET(colIdx, XMATCH(G3,A1:D1), tb, A2:D5, lkCol, INDEX(tb,, colIdx),
INDEX(TAKE(FILTER(tb, (A2:A5=G2) * (lkCol<>0), "Not Found"),1),colidx)
)
and here is the output:
We use LET for easier reading and composition. First we need to identify the column of our interest. The name colIdx, has the column index. Notice in order to deal with only one data range (tb), I search in all column names including Name. Now we need to identify the corresponding column values. The name lkCol represents that.
Now we have all the elements we need to filter and select the information we are looking for:
FILTER(tb, (A2:A5=G2) * (lkCol<>0), "Not Found")
The output will be the rows from tb for name G2 and filtered for non empty rows from G3 column name. The output has all the columns, now we need to select the column of our interest and only the first non empty value. TAKE extracts only the first row and INDEX the corresponding column.

Related

How to print a value in table after checking 2 conditions

I have a table with time on the left and number of houses on top. i want to print a value for a specific house in a specific time. i am using vlookup to match the house and the value but unable to match it with time. as seen in the screenshot the value should only b printed fron 12:15 to 12:45. formula i am using is =IFERROR(VLOOKUP(I$10,$B$3:$C$3,2,FALSE),""). Can anyone help to point me in the right direction.
workbook is attached for sample.
sample workbook
Try this in I11 then fill right and down.
=IF(AND($H11>=$B$6, $H11<=$C$6, I$10=$B$3), $C$3, TEXT(,))
Can you try using INDEX of your table, once you know which row and column you want?
You can then get the row and column number from within your range by using MATCH, for example:
column number: =MATCH(10,[housesRange],0)
and
row number: =MATCH([time],[timeRange],0)
This can be combined with index:
=INDEX([fullTable],[rowNumber],[columnNumber])
Assuming you're looking for a 2 dimensional search of the table, you should use vlookup and match:
Let's for the answer's sake define the table range as
A1:J10
the column number (house number) cell is:
I1
and the start time cell is:
I2
vlookup, does a search on a column and returns a result from the found row in a defined column
to find the column to return, we can use match, match would return the column number of a value, so in this case:
=MATCH(I1,A1:A10,0)
The last parameter, 0, refers to an exact match.
with a vlookup, we have the 2d search:
=VLOOKUP(I2,MATCH(I1,A1:A10,0), 1)
Since the time is set as range, I defined the last parameter of vlookup as 1, so it will found the closest time to the search parameter
Hope that helps

Search a date in multiple date ranges and return the corresponding value

In sheet 1, I have a list of dates in Column A in chronological order. There are values corresponding to this list in Column B. There is another list of dates in sheet 2 and I want to add values from sheet 1 to these dates.
Sheet 1.
**Column A Column B
DATE Amount**
1. 10/01/2015 25,60,000
2. 10/02/2015 26,80,000
3. 01/03/2015 21,55,000
4. 30/03/2015 24,60,500
5. 30/04/2015 28,20,000
6. 30/06/2015 19,00,000
Sheet 2.
Column A Column B
1. 21/02/2015 21,55,000
2. 15/01/2015
3. 20/05/2015
4. 25/04/2015
For example: I need to look up 21/02/2015 in sheet 1 and column A and return the value corresponding to the next available date. So for 21/02/2015 I need the value corresponding to the next date available which is 01/03/2015 and the value is 21,55,000. If its 15/01/2015 I need the value of 10/02/2015 i.e. 26,80,000
What formula could I use for this?
You could use VLOOKUP, but it has some issues. So it is better to use INDEX and MATCH combination. In your case try this
=INDEX('Sheet 1'!$B:$B,MATCH(A1,'Sheet 1'!$A:$A,-1))
Sorry, my previous answer works only for descending order. Try this instead
=INDEX('Sheet 1'!$B:$B,MATCH(TRUE,('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1)),0))
Explanation: I hope that INDEX and MATCH are well explained in Office Support.
About the condition:
('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
What it means?
'Sheet 1'!$A:$A-A1
results in a difference between the value in the cell A1 and the cell in A column in Sheet 1.
MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
says that if the difference is non-negative ('Sheet 1'!$A:$A-A1>=0), find the minimum of such numbers (MIN function).
And if these numbers are equal (MATCH function), then pick the corresponding number in column B (INDEX('Sheet 1'!$B:$B,...)).
Apology: In my previous answers I swapped the columns of your example. I hope it is now correct.
You can use vlookup with True rather than the widely used form with False
As ExcelEfendisi said you can use vlookup with range lookup enabled. A simple way to get the value at the next date rather than the prior one would be to push all the amount values down one row, but to avoid that it might be better to repeat the index values - like this
1 10/01/15 25,60,000 1
2 10/02/15 26,80,000 2
3 01/03/15 21,55,000 3
4 30/03/15 24,60,500 4
5 30/04/15 28,20,000 5
6 30/06/15 19,00,000 6
Then you can use two vlookups, the first one to get the index of the row with the date prior to the date you are interested in and a second one to extract the balance value for the subsequent date - not very elegant but it would work
Try this formula (enter in Sheet2 cell B2 then copy till the last record)
=INDEX(Sheet1!$B:$B,1+MATCH($A2,Sheet1!$A:$A,1),1)
As data is sorted in ascending order use MATCH with match type 1 (less than) to obtain the row above the high next item, then add 1 and the result is the high next row, use this row to get the corresponding record from the column B with formula INDEX

Excels INDEX MATCH - Finding multiple matches

------A ----------------- B ----------------------C ------------------------D
1 --First--------------Last-----------------Start Date--------------End Date
2 --John--------------Smith--------------08/08/2014------------01/01/2015
3---John--------------Smith--------------08/11/2014------------17/11/2014
4---John--------------Smith--------------06/06/2014------------23/12/2014
5---Abel--------------Jones--------------14/05/2014------------29/04/2015
6---Abel--------------Jones--------------04/07/2014------------26/04/2015
Sometimes on my spread sheet I get duplicate names. For example the table above (with random data) there are 3 John's and 2 Abel's. With these names is a start and end date. If I have a start or end date which is earlier or later than the previous entry for that name, I would calculate the longest range (John Smith) by doing
=MAX($D2:$D4)-MIN($C2:$C4)
This would give 209 days.
Also, I want the formula to automatically recognize if a name has a duplicate within the range, and if so retrieve the date. In order to do this, I perform an INDEX MATCH function as follows.
=INDEX(C:C,
MATCH(1,INDEX((A:A=$A3)*(B:B=$B3),0),0))
This should give 08/08/2014.
So then I combine the two formulas together to perform a search for first name and last name comparing the start and end date of the matches, to find the longest possible date range.
=MAX(
(INDEX($C:$C,
MATCH(1,INDEX(($A:$A=$A4)*($B:$B=$B4),0),0)))
:$D4)
-
MIN(
(INDEX($D:$D,
MATCH(1,INDEX(($A:$A=$A4)*($B:$B=$B4),0),0)))
:$C4)
Again this gives 209.
The problem which I am now having with this formula, is that when the INDEX MATCH function scans through the list of names to find a duplicate, if it does, it will only match against the first. If there is more than one duplicate, it will ignore it. There are 3 John Smiths in the table, I want the formula to check for the longest range between all duplicates.
Does this make sense and is this possible?
I would define the ranges more surgically when using array formulas. Given the small data set, this array formula gives the expected result:
=MAX(IF(INDEX($A$2:$A$6&" "&$B$2:$B$6, 0) = A2&" "&B2, $D$2:$D$6)) - MIN(IF(INDEX($A$2:$A$6&" "&$B$2:$B$6, 0) = A2&" "&B2, $C$2:$C$6))
...confirmed with Control+Shift+Enter to activate the array.

Excel - Custom Lookup

I am having a really tough time finding a way to pull data from one sheet to another for a specific task.
On sheet1 I have 42005 (jan 1, 2015) in A1 and it goes to 42735 (Dec 31, 2016)
------A1------|42005|42006|42007|42008|...
Employee 1|-Yes--|-Yes--|-Yes--|-Yes-|...
Employee 1|-Yes--|-Yes--|-Yes--|-Yes-|...
I Need a "Yes", "No", or "Different Unique ID" to show up in the above list in the second row for conditional formatting from the data below. If the date in the header is listed in the bottom table, then i need a unique ID.
On sheet2 I have date ranges that employees work (45 days at work and 7 days off, for example)
Employee 1 | Employee 1 0.01| Employee 2 | Employee 2 0.01
Start--------- | End-----------------|Start-----------|End
42005------- | 42049---------------|42005---------|42049
45------------ | 10--------------------|45--------------|10
42060------- | 42104---------------|42060---------|42104
45 ----------- | 10--------------------|45--------------|10
42115------- | 42159---------------|42115---------|42159
45 ----------- | 10--------------------|45--------------|10
I need a way to match the current date to the start and end dates that are listed, they need unique ID as the result of an IF function for conditional formatting. This notes that it is either the beginning date or the end date which is considered a "travel day".
Basically, I need B2 in the top example to say IF an exact match of the above date in A2 can be found in column1 or column2 of employee 1's [section] in the table, then "unique ID". What I cant figure out is how to search in BOTH employee 1 and employee 1 0.01 columns depending on the name field in the top.
The name column in the top example is a list drop down, so i have to find a dynamic formula for this. Manually assigning a range to each cells lookup fields wouldn't work.
=HLOOKUP(B$2,Sheet2!$A$1:$GR$340,MATCH($A2,Sheet2!$A$1:$GR$1),FALSE)>=100,18, "false")
Clearly that doesn't work, but was an idea to try to get the search in the right area. No way i can find the correct column for the name, then select that column +340 rows, and +1 column to the right for the proper range, then look for specific value?
Is there a way to achieve this?
If I understand this correctly, you can solve this along these lines:
Find the column matching the employee name
Search the column to see if there is a match to the date value.
If there is no match, then search the next column to the right for a matching date value.
If there is no match in the second column, then return a value to indicate failure.
This formula is going to be really long and complicated so I'll break it up as best I can. You can start by finding the column matching the employee with a match function. This will return the column number.
=match(EmployeeName, EmployeeNames, 0)
Next, we'll want to search this column with a vlookup but you have to refer to the column by column number and not by letter. To do that, use indirect(address()). Address works by using the row number and column number to refer to a cell. We'll use one for the start of the column and one for the end of the column. Plug in the match formula from above and we have the range to search.
=vlookup(DateValue,indirect(Address(1,match(EmployeeName,EmployeeNames,0))):indirect(address(500,match(EmployeeName,EmployeeNames,0))),1,0)
Note that I used 500 as the end of last row of the column to be searched. You can make it more if needed.
So far this formula will return the date if the date is found in the first column matching the employee name and an error if there is no match. We still have to search the second column if there wasn't a match. I like to use the iferror() function for this. Put the formula above as the first argument of the iferror and also as the second. We'll modify the second to search the next column over. Since we are using the column numbers, we can just increment over by adding 1 to the column.
=iferror(vlookup(DateValue,indirect(Address(1,match(EmployeeName,EmployeeNames,0))):indirect(address(500,match(EmployeeName,EmployeeNames,0))),1,0), vlookup(DateValue,indirect(Address(1,match(EmployeeName,EmployeeNames,0)+1)):indirect(address(500,match(EmployeeName,EmployeeNames,0)+1)),1,0).
Almost there, now we have to handle the error if nothing is found in the second column as well. Wrap the second vlookup in an iferror and some constant at the end.
=iferror(vlookup(DateValue,indirect(Address(1,match(EmployeeName,EmployeeNames,0))):indirect(address(500,match(EmployeeName,EmployeeNames,0))),1,0),iferror( vlookup(DateValue,indirect(Address(1,match(EmployeeName,EmployeeNames,0)+1)):indirect(address(500,match(EmployeeName,EmployeeNames,0)+1)),1,0),"No Match").
When you set up the conditional formatting, you would set the formula to check if the cell value is (or is not) "No Match".

Find something in column A then show the value of B for that row in Excel 2010

Basically my problem is that I have a string in one cell in excel, I then need to see if that string exists in another row (not one cell but the whole row) and if so then print the contents of another cell in the same row but in another column.
I will give a basic example:
Title Answer
Police 15
Ambulance 20
Fire 89
Now I need to scan the title column for, say, "Police" and then populate the cell with the value under Answer (in this case 15).
I cant just say IF(A2="Police";B2;"" as I need the scan the whole of the Title column.
I have tried using IF(COUNTIF(A$2:A$100;"Police"); which scans the contents of A2 to A100 for the string Police, and know how to make it print a constant (just put something after the ;) but cant work out how to make that "constant" a variable that changes depending on the found row. So if the COUNTIF found Police in cell A44 then the answer to my formula would be B44, the same as if it found Police in A62 then my formula should show B62
I hope this makes sense and that someone can help me :)
Note that I am using excel 2010 and need a normal formula as I can not use scripting for this document.
EDIT:
Here is what I have so far, note that the spreadsheet I am using is far more complex than the "simple" example I have in the question...
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
This is showing "RuhrP" in every answer where "RuhrP" is found in F9 and not the answer I want which should be that found in RuhrPumpen!I$5:I$100 where the cell index is the same as that for the A coloum where A9 was found. Again, sorry for the complexity I cant think of any better way to word it.
I note you suggested this formula
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
.....but LOOKUP isn't appropriate here because I assume you want an exact match (LOOKUP won't guarantee that and also data in lookup range has to be sorted), so VLOOKUP or INDEX/MATCH would be better....and you can also use IFERROR to avoid the IF function, i.e
=IFERROR(VLOOKUP(A9;Ruhrpumpen!A$5:Z$100;9;0);"")
Note: VLOOKUP always looks up the lookup value (A9) in the first column of the "table array" and returns a value from the nth column of the "table array" where n is defined by col_index_num, in this case 9
INDEX/MATCH is sometimes more flexible because you can explicitly define the lookup column and the return column (and return column can be to the left of the lookup column which can't be the case in VLOOKUP), so that would look like this:
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH(A9;Ruhrpumpen!A$5:A$100;0));"")
INDEX/MATCH also allows you to more easily return multiple values from different columns, e.g. by using $ signs in front of A9 and the lookup range Ruhrpumpen!A$5:A$100, i.e.
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH($A9;Ruhrpumpen!$A$5:$A$100;0));"")
this version can be dragged across to get successive values from column I, column J, column K etc.....
Assuming
source data range is A1:B100.
query cell is D1 (here you will input Police or Fire).
result cell is E1
Formula in E1 = VLOOKUP(D1, A1:B100, 2, FALSE)
I figured out such data design:
Main sheet:
Column A: Pump codes (numbers)
Column B: formula showing a corresponding row in sheet 'Ruhrpumpen'
=ROW(Pump_codes)+MATCH(A2;Ruhrpumpen!$I$5:$I$100;0)
Formulae have ";" instead of ",", it should be also German notation. If not, pleace replace.
Column C: formula showing data in 'Ruhrpumpen' column A from a row found by formula in col B
=INDIRECT("Ruhrpumpen!A"&$B2)
Column D: formula showing data in 'Ruhrpumpen' column B from a row found by formula in col B:
=INDIRECT("Ruhrpumpen!B"&$B2)
Sheet 'Ruhrpumpen':
Column A: some data about a certain pump
Column B: some more data
Column I: pump codes. Beginning of the list includes defined name 'Pump_codes' used by the formula in column B of the main sheet.
Spreadsheet example: http://www.bumpclub.ee/~jyri_r/Excel/Data_from_other_sheet_by_code_row.xls
Guys Its very interesting to know that many of us face the problem of replication of lookup value while using the Vlookup/Index with Match or Hlookup.... If we have duplicate value in a cell we all know, Vlookup will pick up against the first item would be matching in loopkup array....So here is solution for you all...
e.g.
in Column A we have field called company....
Column A Column B Column C
Company_Name Value
Monster 25000
Naukri 30000
WNS 80000
American Express 40000
Bank of America 50000
Alcatel Lucent 35000
Google 75000
Microsoft 60000
Monster 35000
Bank of America 15000
Now if you lookup the above dataset, you would see the duplicity is in Company Name at Row No# 10 & 11. So if you put the vlookup, the data will be picking up which comes first..But if you use the below formula, you can make your lookup value Unique and can pick any data easily without having any dispute or facing any problem
Put the formula in C2.........A2&"_"&COUNTIF(A2:$A$2,A2)..........Result will be Monster_1 for first line item and for row no 10 & 11.....Monster_2, Bank of America_2 respectively....Here you go now you have the unique value so now you can pick any data easily now..
Cheers!!!
Anil Dhawan

Resources