How to find earlier date in google spreadsheets? - google-sheets

in Google Spreadsheets I have a column A with dates and column B with specific values corresponding these dates:
A
B
10-Jan
51.1
11-Jan
49.2
14-Jan
50.3
If I find via VLOOKUP function the value of 11-Jan, it will work and show 49.2.
Off cause it won't work if I try to find a value of 13-Jan since it is absent from the list of dates. However, if the date is absent in column A I want to get the value of earlier date which is in the list (i.e. I want to get 49.2 corresponding to 11-Jan, if I use 13-Jan as the query for finding the value).
Maybe this type of search can be realized by using INDIRECT function, but I can't figure out the formula.
How do realize this?

Your problem can be solved by using vlookup only but with different parameter, if you indicate True for the last parameter, it mean the formula will try to return the closer match if it cannot found any result.
=arrayformula(VLOOKUP(E1:E5,A:B,2,True))

Related

Google Sheets – Query for a date returns no values

​​I'm trying to filter a list from another sheet by the dates of the entries and simply doesn't work:
=QUERY(Import!A:Z;"select A,T where T >= date '2021-08-27'";0)
​When I remove the date part it works fine, as expexted for filtering by text. I need the ability to sort by exact dates though, because I would like to add some more complex filters. When I set the last part of the function to a 0 instead of a 1 it shows only the first entry.
The source column is set to the correct date format. The data is pulled from another document using the IMPORTRANGE()​ function (I don't seee how this should make any difference though).
I feel like I'm misssing something simple here and would be glad if someone can point me in the right direction!
Check your date column if all cells are formatted as date. I had missing values as "='---" and the query filtering by date returned nothing. Changing the missing values to "=NA()" did the job.
Try this:
=QUERY(Import!A:Z;"select A,T where T >= date '"&TEXT("2021-08-27";"yyyy-mm-dd")&"'")

regexmatch doesn't seem to work with minifs in Google Sheets

I'm trying to find the min date for sub-tasks that are related to the same Task ID.
Because I want to leave the task min date cell blank if none of the sub-tasks have a date entered, I use the following formula:
=if(SUMPRODUCT(regexmatch($A18:$A,"^Sub-Task "&$B16&".[0-9]"),$F18:$F=$F16,G18:G<>"")<>0,minifs(G18:G,$A18:$A,regexmatch($A18:$A,"^Sub-Task "&$B16&".[0-9]"),$F18:$F,$F16,G18:G,"<>"),"")
This breaks downs as follows:
In the SUMPRODUCT function
I use regexmatch($A18:$A,"^Sub-Task "&$B16&".[0-9]*") to check that I only look at sub-tasks that have the same ID as the specific task "B16"
I use $F18:$F=$F16 to check that I only look for "Planned" dates, which is in "F16" instead of "Actual" dates
I use G18:G<>"" to check that I only look for date cells that aren't empty
If the sumproduct results in something, I then use the minifs() function to find the min value of the result.
IF the sumproduct results in nothing, I enter blank "" in the cell
The sumproduct seems to work perfectly well and gives me the results that I expect when I change values around, but the minifs function doesn't seem to work with regexmatch()
Is there a different syntax that has to be used in minifs functions?
try:
REGEXMATCH(A18:A&"", "^Sub-Task "&B16&".*")
inserting numeric value in regex will cause VALUE error
Figured it out, minifs can take regex directly, but only simple ones; it doesn't like characters like "^", and I was able to work around it for my needs.

Last value of a column in Google Sheets

I was trying to use the following function;
=INDEX(D:D,COUNTA(D:D),1),
in order to get the last currency value of a column, but it returns #ERROR!.
The value im trying to extract
As I montly update this spreadsheet, it would make it very convenient if would etract the last value in the column, e.g. the value marked in the image.
Is there a way (in Google Sheets) to find the last non-empty cell in this column, such that when I update the spreadsheet with a new "last value" it would return that value?
The index(counta()) pattern will fail when the data is sparse, i.e., when there are blank values in the column.
The index(match()) pattern will fail when the data contains a value that is not a number.
To find the last non-blank value in column D, regardless of data type, use the +sort(row()) pattern:
=+sort(D1:D; not(isblank(D1:D)) * row(D1:D); false)
The formula uses semicolons as argument separators to make it work in any locale.
If the column has only currency (ie number) values then you can use something like:
=INDEX(D1:D, MATCH(999^99, D1:D))
or try:
=SORTN(D:D; 1;;ROW(D:D)*(D:D<>""); )

SUMIFS and/or QUERY inside ARRAYFORMULA

Google spreadsheet sample: https://docs.google.com/spreadsheets/d/1MdRjm5QmKY_vaah9c3GrvH6dDOBCQX_zvCubvN0akmk/edit?usp=sharing
Im trying to get the sum of all values for each ID. The values im trying to add up are found in the Source tab while the calculations are done in the Output. My desired values are based on 2 things: ID and Date. The Id is supposed to match and the Date is supposed to be February. I tried first just using a sumif with just matching ID and it worked using this formula: =ARRAYFORMULA(IF(A2:A="",, SUMIF(Source!A:A,A2:A,Source!B:B)))
But when I add the 2nd critera and use a sumifs function, it only outputs for the first id. Here is the sumifs formula I used: =ARRAYFORMULA(SUMIFS(Source!B2:B,Source!A2:A,A2:A,Source!C2:C,">="&DATE(2021,2,1),Source!C2:C,"<="&DATE(2021,2,28)))
I tried using query as some of the answers I found online suggested to use it but it also outputs the first data only, here is the query formula I used =ARRAYFORMULA(QUERY(Source!A2:C,"select sum(B) where A = '"&Output!A2:A&"' and C >= date '"&TEXT(DATEVALUE("2/1/2021"),"yyyy-mm-dd")&"' and C <= date '"&TEXT(DATEVALUE("2/28/2021"),"yyyy-mm-dd")&"' label sum(B) '' "))
I know this is possible by making a temporary query/filter where you only include desired dates and from there I can use SUMIF, but I will be needing to make a monthly total and making 12 of these calculated temporary filters/query would take up a lot of space since we have a lot of data so I want to avoid this option if possible. Is there a better fix to this situation?
Solved by Astrotia - =arrayformula(sumif(I3:I20&month(K3:K20), A2:A6&2, J3:J20))

Perform a search on range of dates and text fields and return a match for the first column

I have been trying a few solutions but I am pretty stuck. I am trying to find out if a date is included in a named range and return the period name of the corresponding row ( ie value in first column)
I have tried, using match, vlookup, hlookup- but none of them seem to match the value. I have even made sure that both are formatted as date.
Any help would be welcome!
https://docs.google.com/spreadsheets/d/1T3sdrkciyXkOgD23S-5rFvvDbK-bHFlh7yv4LwkpHiQ/edit?usp=sharing
C3:
=ARRAYFORMULA(TEXTJOIN(,1,IF(A3=G$7:AY$19,F$7:F$19,)))
IF to get Column1
TEXTJOIN to remove blanks

Resources