Look up value between dates - google-sheets

I have two tables. One table contains a column with dates and a column with exchange rates. A second table allows a user to enter any date and returns the exchange rate from the other table.
The lookup between the dates should search for the date that is closest to the entered date but never a future date (past or same date). How can I achieve this?

This is what vlookup is for.
=vlookup(D2, A2:B, 2, True)
Here D2 is search key, A2:B the range in which to search (1st column is searched), 2 is the number of column from which to return the result. True means the following:
If is_sorted is TRUE or omitted, the nearest match (less than or equal to the search key) is returned. If all values in the search column are greater than the search key, #N/A is returned.
Also works as an arrayformula, looking up all D values at once:
=arrayformula(vlookup(D2:D3, A2:B, 2, True))

Related

How to find any data from a column in a cell in google sheets?

Is there a way to have a range as a search key in google sheets? Like some sort of IF CONTAINS?
For example:
If column A contains any data listed in Column B, then it should return TRUE else FALSE.
Column A
Column B
Result
a02,bw2,z2
a01
FALSE
z12,x9e,df
b22
FALSE
xz8,aa2,mn
wc2
TRUE
a01,sr8,xf
xz8
TRUE
+1K rows
+1K rows
+1K rows
Tried REGEXMATCH, MATCH, LOOKUPS, FIND but no luck. Tried a range(like the whole column) as a search key, but it kind of concatenates the whole data in the column and uses the whole column as the search key. What I need is for it to use the data in column A as separate search keys. Since there are thousands of data, it would be time consuming to IF VLOOKUP each data.
Use formula:
=if(sumproduct(arrayformula(split(A1,",")=$B$1:$B$4)),TRUE,FALSE)
It splits value in A1 to 3 elements array and compares it to every value in column B you give. It returns 2 dimension array with TRUE or FALSE (this case array is 3x4). SUMPRODUCT of this array will be positive number if at least one value is TRUE.
Result:

Combine / merge contents of columns in Google Sheet into a single column based on a condition

I have a spreadsheet with multiple columns. Each column represents a recipe. Each column has a week number (e.g. 2, 3, 4)... Below the week number, we have a variable number of ingredients. I want to be able to merge all the ingredients from a given week into a single column.
Sample Data
I know how to statically merge ranges e.g. {B4:B20;C4:C20} and I can also think of using an if statement to check the week value e.g. =if(B1=2,{B4:B20;C4:C20}) but that's not close to what I want. I need to check the range B1:Z1 for the value of the week and if that value is X (let's say 2) then take the ingredients in B2:B and tack them on to C2:C and so on...
If I'm understanding you correctly, this should do it:
=QUERY(FLATTEN(FILTER(B3:Z,B1:Z1=2)),"WHERE Col1 Is Not Null")
FILTER keeps (i.e., "filters in") only the data in B3:Z where the header is 2.
FLATTEN forms one column (blank cells and all) from the FILTER results.
QUERY keeps only non-blank (i.e., Is Not Null) entries from that single-column list.

Third Parameter in Array Formula to check for highest(max) occurence but only if the other conditions are true first

Ok, this is the updated linkI have multiple criteria to look through in my arrayformula(index(match())). The first two are simple as they reference the row the formula is calculating on. The last conditional I have is to find the highest occurrence in a given range, but ONLY if the other conditions are met...something like a filtered maxifs..any ideas?
Here is my code in column P =iferror(ArrayFormula(index($F:$F,match(1,("Fee Taken"=$C:$C)*(H12=$H:$H)(maxifs($M:$M,$H:$H,H2,$C:$C,"Fee Taken"),0))),""))
The result that I would like is to return from column F if the name matches that rows name, the transaction type is "Fee Taken" from column C, and THEN if those conditions are true I want it to find the max value from column M based on those two criterias and return the column F value for that max value row..
Ive attached some pictues to show my data.
The last part of the Match function where I have the Maxifs equaling to eachother is where I am confused; my thoughts were to see if the maxifs for the item in Column "M" can be used as a criteria..but I do not think so....I only want the highest occurence F:F if both conditions are met and it is the highest value for both those criteria in column M..
Please let me know if you need anymore info..Thanks![
Working formula will be:
=ArrayFormula(index($F:$F,match(1,--(M:M=(maxifs($M:$M,$H:$H,H2,$C:$C,"Fee Taken"))),0)))

In Google Sheets, I want to populate cells in Column A with certain conditions, based on the contents of column B

In this sheet,
https://docs.google.com/spreadsheets/d/1MR0n1FoutASbuwiNJS7FrcQhxHF6Bo03oVs9RZPo9g4/edit?usp=sharing
I am trying to have column B be populated with cell values equal to is today's date or tomorrow's date, by referencing column F.
Then, I am trying to have column A be populated with the contents of column E, based on if the column E's item is for today or tomorrow (Basically if the item's corresponding date shows up in B).
I've tried playing with index, lookup and filter but I cannot manage to get the formula right, and when using index and lookup there are many empty cells in between the dates.
I would appreciate any help.
I added a sheet ("Erik Help") with the following formula in A1:
=ArrayFormula(IFERROR(FILTER(E:F,(F:F=TODAY())+(F:F=TODAY()+1))))
That one formula returns all results you wanted to see.
Explanation:
The key part to understand is the condition that FILTER is using to filter in entries; and that is (...) + (...). The plus sign is the equivalent of OR in an array. So it's basically saying, "Filter in all results from E:F where (F:F = today) OR (F:F = tomorrow)." And if there is no match at all found for that OR condition, IFERROR will just return nothing (rather than an error).
Reference:
FILTER

How to do VLOOKUP based on multiple criteria and return the latest rows result?

Currently when I use Vlookup, it provides for first matching occurrence of data.
I receive data into a spreadsheet by date, i.e., a record existing for every project with values for status field. I build a consolidated report in a new tab at project level, I need to populate the 'STATUS' column for each project.
The status field value could remain same for few days but would change on a certain date. If I use VLOOKP(Project#, SampleData! Project#:Status, 7 , 0) I would get for first match i.e., most likely will get always 'In-Progress' as result
How can I add another criteria in VLOOKUP to search for max of dates upon the matching project# & return the result?
Google Sheet Link
If projects are sorted by date in ascending order, you can use LOOKUP function to get last status:
=ArrayFormula(LOOKUP(2,1/(A11=$B$2:$B$7),$H$2:$H$7))
if not sorted, then try following:
=ArrayFormula(LOOKUP(2,1/((A11=$B$2:$B$7)*(MAX($A$2:$A$7*(A11=$B$2:$B$7))=$A$2:$A$7)),$H$2:$H$7))
Explanation:
Here is used LOOKUP feature if search key is not found, the lookup will return the last closest matching key in the range with a lower value. In first formula LOOKUP search for value 2 while expression 1/(A11=$B$2:$B$7) returns array with errors and ones {1/TRUE,1/TRUE,1/TRUE,1/FALSE,1/FALSE,1/FALSE} => {1,1,1,DIV/0,DIV/0,DIV/0} so LOOKUP returns value from third row in range $H$2:$H$7.
In the second formula, by analogy.
Using VLOOKUP
Leveraging the ARRAYFORMULA function you can build a search_key for your range:
This will basically multiply the Boolean result of the EQ function (=) for all the possible dates and then take the maximum.
Note: Boolean values are also represented as 1 for TRUE and 0 for FALSE, so every date that is not for the corresponding Project code will result in a very old timestamp.
I will then use this as a search_key to get the status (col 8) for the Project code subset range (built with the IF function):
=ARRAYFORMULA(
VLOOKUP(
MAX($A$2:$A$7*(A11=$B$2:$B$7)),
IF(A11=$B$2:$B$7, $A$2:$H$7),
8,
FALSE
)
)
Dragging down this formula for each project code will return its last status.
Using QUERY
If you prefer to use the QUERY formula instead of the VLOOKUP here is an example:
The query is based on a sub-query that basically leverages the max() aggregate function to find the max date for a specific Project code.
Then it uses this maximum date and the Project code as a key to be sure to exclude date duplicates that belong to other Project codes.
=QUERY(
$A$1:$H$7,
"select H where A = date '"& TEXT(
Query(
$A$2:$H$7,
"select max(A) where B = "&A11&" label max(A) ''",
1
),
"yyyy-MM-dd")&"'",
0
)
Here as well dragging down the formula will return the Project last status.
References
VLOOKUP
QUERY
IF

Resources