Excel - Custom Lookup - excel

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".

Related

Nested Xlookup First Non-blank Cells

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.

Formula to get all matching values and return all occurrences of match in order based on 1st occurrence of a value in another column

This one is interesting and I am not even sure if it can be done with a formula. I can do it with a macro but I want a formula for this one.
I have 2 sets of data. The 1st set contains some dates and a true/false field and an ID number. The 2nd set of data contains some dates and ID number and a blank column. Now I need to find the 1st occurrence of an ID number in the 2nd dataset and then based on that check the 1st dataset for matching numbers and then check if value is false in the 3rd column. If that value is false return date from 2nd column.
Now I can go this on my own with a vlookup if I only wanted the 1st occurrence but I need to get all matches. The dates in the 2nd column can be ignored they are not part of the formula.
Here is an example of what the data should look like after applying the formula. I need the false dates to be returned. I know I can build this as a function but I really need to do a formula if possible.
Update:
I did find JOINTEXT() however that does not work in excel 2013 :| so that is out of the question.
You can use INDEX and AGGREGATE combination:
=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW(A:A)/((G2=A:A)*(0=--(C:C))),COUNTIF($G$2:G2,G2))),"")
In my example in column C are boolean values. If you have text there then change part of formula (0=--(C:C)) to ("FALSE"=C:C)

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 column for text value, if value exists check other column for number of days from the date today?

I have an Excel spreadsheet like so:
A B
27/03/2015 Riddor
28/03/2015 Text
09/03/2015 Bees
What I am trying to do is search my column B for the word Riddor using this function:
=IF(ISERROR(MATCH("Riddor",Statistics!B:B,0)),"No Match",TODAY()-MIN(Statistics!B:B))
Within this function if the value Riddor is not found I want to show 'no match' else if the value is found I want to identify the most recent occurrence of the value Riddor in my column where its date in column A is the most recent from today. I then want to count the number of days.
So for instance my value Riddor in column B has a date of 27/03/2015. The number of days from this date to today is 5, however if I add another Riddor with a more recent date like so:
27/03/2015
31/03/2015
then I want my day count to show 1 day instead of the previous 5 days.
Can someone please show me where I am going wrong and what to do to get this working?
You will need to use a formula as defined below
Note that the flower brackets indicate that you are using this as a range formula which means you will need to hit Shift+Control+Enter and when you click on that Cell it will create the flower brackets in the end.
The below formula will retrieve the MAX Date the next part is quite simple you need to subtract from today to arrive at the difference in days. Preferably do it in another cell. I have accounted for different sheets in a modified formula at the bottom of this post. But you can test the below on the same sheet and then copy over the cell to another sheet to have it dynamically correct to account for sheet if you like. Either ways the below is tested with all events and is working
{=IF(COUNTIF(B:B,"Riddor")=0,"No Match",IF(COUNTIF(B:B,"Riddor")=1,INDIRECT("A"&MATCH("Riddor",B:B,0)),MAX(IF(B:B="Riddor",A:A))))}
Explanation
Part I - =IF(COUNTIF(B:B,"Riddor")=0,"No Match" Counts if there are any occurance of the word Riddor in that Range
Part II - IF(COUNTIF(B:B,"Riddor")=1,INDIRECT("A"&MATCH("Riddor",B:B,0)) this part accounts if there is only once occurance of the word Riddor then it uses the Match function to retrieve the date from the A Column. It would be easier with VLOOKUP but I'm assuming you dont want to change the Column Order for A & B
Part III - MAX(IF(B:B="Riddor",A:A)))) This where the Range formula is actually required. It checks in the Range B:B and Retrieves all the Dates where the B Column Matches "Riddor" and then Finds the Max date in that subset Range which would be the date closest to today's date.
Tested and Working perfectly in sample provided by your even with Multiple instances of Riddor.
Formula Accounting for the difference in Sheets not tested yet.
{=IF(COUNTIF(Statistics!B:B,"Riddor")=0,"No Match",IF(COUNTIF(Statistics!B:B,"Riddor")=1,INDIRECT("Statistics!A"&MATCH("Riddor",Statistics!B:B,0)),MAX(IF(Statistics!B:B="Riddor",Statistics!A:A))))}

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