vlookup does not show date search - google-sheets

I am trying to vlookup a date in a range of text, numbers, dates. vlookup search for number days of a given date, tried to change the number to date, but it does not work.
my formula is =vlookup(date(2022,7,5),A:C,1,false) for the below table. and it should show value text5.
| A B C
---------------------------
1 | text1 7/1/2022 001
2 | text2 7/2/2022 002
3 | text3 7/3/2022 003
4 | text4 7/4/2022 004
5 | text5 7/5/2022 005
It shows #N/A and the Error message was Did not find value '44747' in VLOOKUP evaluation.
I thought it was days and I need to change it to date format. to be =vlookup(to_date(date(2022,7,5)),A:C,1,false). the same problem.

VLOOKUP() will not work in this case, because VLOOKUP() always search on first column and your first column is text field and dates are on second column. So, use INDEX()/MATCH() instead. Try-
=INDEX(A:A,MATCH(DATE(2022,7,5),B:B,0))
Also FILTER(), QUERY() functions will work in your case.

Related

Calculate Days between series of dates in a range

I wanted to calculate the difference of numbers that are inputted in a Google sheet row like this:
Row 1: 35 | 37 | 39 | 38 and So on (until last non-empty cell)...
And the output would be:
Row 1 Output: (37-35)+(39-37)+(38-39) = (2+2-1)=3
the suggested formula for this calculation is:
=LAMBDA(rg,SUMPRODUCT(rg-OFFSET(rg,0,-1)))(INDEX(1:1,2):INDEX(1:1,COUNTA(1:1)))
Taking forward to this concept, now I want to calculate days between dates instead of numbers.
something like this (date format:yyy-mm-dd):
Row 1: (blank cell) | 2022-07-06 | (blank cell) | 2022-07-07 | 2022-07-08 and So on (until last non-empty cell)...
Expected Row 1 Output:(2022-07-07-2022-07-06)+(2022-07-08-2022-07-07) = (1+1)=2
I used the above formula but I reckon formula is producing incorrect output because it does not exclude blank cells in between these dates, that's why it gives 44749 an an output,image is also attached:
Here is the how the table looks like in sample sheet in case you want to test it.
Desired Output (No. of Days)
Date1
Date2
Date3
Date4
Date5
Date6
3
2022-07-06
2022-07-07
2022-07-08
2022-07-09
(G2-E2)+(E2-D2)+(D2-B2)
1
2022-07-06
2022-07-07
(G4-C4)
Table is starting from column A to Column G. Any guidance would be much appreciated, thank you.
There are many ways of finding the first and last non-blank cell in a row, but let's use xlookup for the sake of argument:
=ArrayFormula(xlookup(true,(B2:2<>""),B2:2,,0,-1)-xlookup(true,(B2:2<>""),B2:2,,0,+1))
But people just don't believe me when I tell them that (G2-E2)+(E2-D2)+(D2-B2) simplifies to G2-B2. It's basic algebra folks!
Or this is equivalent to my original formula but doesn't lend itself to being written as an array formula:
=index(filter(B2:2,B2:2<>""),count(B2:2))-index(filter(B2:2,B2:2<>""),1)
EDIT
Possible array formula (but could be a bit inefficient):
=iferror(byrow(B2:Z,lambda(r,index(filter(r,r<>""),count(r))-index(filter(r,r<>""),1))))
Also if dates are in ascending order left to right (or more exactly, if the first date is the smallest and the last date the largest), and because min and max ignore blanks, you can simplify the original formula to:
=max(B2:2)-min(B2:2)
or with byrow:
=ArrayFormula(byrow(B2:Z,lambda(r,if(min(r)=0,,max(r)-min(r)))))

Can I filter out pivot table results that only have one row for a value in column A?

I created a pivot table in googlesheets, and it returns results that look like:
first | second | CountOf3
--------------------------
thing | value | 23
| newVal | 3
| cool | 34
that | value | 234
otherThing | cool | 4
| newVal | 345
And I want to filter out results with just one resulting row for the item in the first column.
So in this example, that would be the row: that | value | 234.
I would like the filter to remove that row, and leave the remaining rows. This is a pivot table in a 2nd sheet that updates when Sheet1 changes.
I have been trying all day, and have not been able to come up with a solution. I was hoping there would be some sort of filter, or spreadsheet formula to do this. I've tried multiple combinations of filters, but nothing seems to work - I'm starting to wonder if this is even possible.
It isn't pretty, but a brute force way is to have a check column beside your pivot table, with this formula on the first data row, ie beside "thing | value | 23".
It flags each row where the subsequent cell in column D is not blank. Then use a query (or filter) to list only the output rows you want. Note that you would hide the columns or rows with the actual (unfiltered) pivot output.
This is the simplest version, to see the logic:
=AND(LEN(D3),LEN(D4))
which results in a TRUE value for pivot chart rows that only have one value.
A more elegant version is an arrayformula, adds the header lable, and uses "Skip" as the flag for which rows to filter out.
={"Better Check";ARRAYFORMULA(IF(LEN(D3:D998)*LEN(D4:D999)*LEN(E3:E998),"Skip",))}
Note that this formula allows for a pivot table result effectively to the bottom of the sheet, but it does have a finite range, due to the constraint of checking two rows at once. It could be enhanced by using a COUNTA on the third data column to measure the exact length of the pivot table results and control the range dynamically, Like this:
={"Better Check";
ARRAYFORMULA( IF( LEN(INDIRECT("D3:D" & (COUNTA(F$3:F)+ROW(F$2)))) *
LEN(INDIRECT("D4:D" & (COUNTA(F$3:F)+1+ROW(F$2)))),
"Skip",))}
Let us know if this helps at all.

sumif with variables in hour format

Well I'm using sumif in google sheet and I'm facing this issue. For my case I want to sum all the numbers according with specific parameters, so SUMIF should answer. But the numbers in the table that should be counted are in hours.
As example =SUMIF($B:$B,9,F:F) where 9 the month, summing all the numbers in the column F. But in F the numbers are displayed as 4:00:00 :
| B | F |
| --- | --------- |
| 9 | 4:00:00 |
| 9 | 4:00:00 |
| 9 | 4:00:00 |
using the sumif it was supposed to return 12, the number of hours spend working, but instead returns 0.5. If I put '4' instead of '4:00:00' I can solve the problem. But How I can do the math using the hour format?
Short answer
=ArrayFormula(SUM(FILTER(HOUR(F:F),B:B=9)))
Explanation
Google Sheets use serialized numbers for dates and time, using a day as the unit. The result of the OP formula is 0.5 = 1/2 day = 12 hours.
To have as result 12, first we could use HOUR function but SUMIF requires a range as argument, not arrays.
An alternative solution is to change the format of the cell having the formula use the same format as F:F, so a value of 0.5 will be displayed as 12:00:00.
I was able to find an alternate solution. You can select the output range. And click on Format -> Number -> Duration. It will show in hour format.

Vlookup on ID and Date (Fuzzy on Date) Google Spreadsheets?

I'm trying to essentially do a Vlookup on two columns ID (where I want the match to be exact) and a date field (where I want it to be fuzzy).
Suppose you have a table in "Sheet1" about hospital admissions like so:
ID Admit_Date
000 01/01/2016
000 06/01/2016
001 02/01/2016
002 04/01/2016
Then I have another table in "Sheet2" about followup care like so:
ID Followup_Date
000 01/05/2016
000 06/06/2016
001 02/02/2016
002 04/04/2016
In sheet 1 I want to return the corresponding Followup_Date which is the closest Date After the Admit_Date
So my final result will look something like
ID Admit_Date Followup_Date
000 01/01/2016 01/05/2016
000 06/01/2016 06/06/2016
001 02/01/2016 02/02/2016
002 04/01/2016 04/04/2016
What's the best way to do this using a formula in Google Spreadsheets?
Update
Get " Followup_Date", formula on Sheet1
You could use this formula:
=QUERY(SORT(FILTER(sheet2!B:B,sheet2!A:A=A2,sheet2!B:B>=B2)),"limit 1")
Original (wrong) answer
Get "Admit_Date", formula on Sheet2
try this formula:
=VLOOKUP(B2,(FILTER(sheet1!B:B,sheet1!A:A=A2)),1)
you'll need to paste it in cell C2 and copy it down.
This formula is doing:
filtering data, doing exact match sheet1!A:A=A2
doind vlookup, with default parameter, that gives the closest Date After the Admit_Date. This will work with numbers, and date is serial number in spreadsheets, so this will fit you.
If you like big ArrayFormulas, here's one, that you don't need to drag down, it'll expand automatically:
=ArrayFormula(RIGHT(VLOOKUP(VLOOKUP(OFFSET(A1,1,,counta(A2:A)),{UNIQUE(FILTER(A2:A,A2:A<>"")),row(INDIRECT("A1:A"&COUNTUNIQUE(A2:A)))*100000},2,0)+OFFSET(B1,1,,counta(A2:A)),VLOOKUP(OFFSET(sheet1!A1,1,,counta(sheet1!A2:A)),{UNIQUE(FILTER(A2:A,A2:A<>"")),row(INDIRECT("A1:A"&COUNTUNIQUE(A2:A)))*100000},2,0)+OFFSET(sheet1!B1,1,,counta(sheet1!A2:A)),1),5)*1)

Display a range of filtered values as a comma-delimited list in one cell on a Google sheet?

Two sheets, one called Core Data, one called Schedule. The Schedule sheet needs to take information about deadlines from Core Data and display it concatenated in deadline-order. (Simple example with numbers and letters instead of dates and tasks given below.)
Here's what I have so far in 'Schedule' (cell B2 specifically in this case):
=JOIN(", ", FILTER('Core Data'!A2:A, 'Core Data'!B2:B=A2))
It's saying no matches are found so I assume this is a problem with the filter component of the formula. However, I've checked the help pages and can't see a problem with the condition I've created.
The formula should:
Get all the values in the given range (cells A2 downward on a 'Core Data' sheet),
Filter them so that only those with certain values are selected. (The information from 'Core Data' should only be selected if the date in the same row on column B matches the date in the cell in the A column on the Schedule sheet.)
Join all these values together and list them as a comma-delimited list.
Example (without dates, for ease):
Core Data sheet:
A | B
-----
a | 5
b | 7
c | 5
d | 3
Schedule sheet (or what it should look like):
A | B
---------
3 | d
5 | a, c
7 | b
Any idea what is going wrong with my formula or if there is an easier way to solve this problem?
The error message I was getting in the cell is:
Error: No matches are found in FILTER evaluation.
It turns out that the cell I was trying this formula on simply had no matches from the filter (no dates corresponded) but instead of returning empty it threw an error. This sounds simple but it's an annoying quirk for me that the cell didn't end up empty which made me assume the formula was at fault.
While the example in the question works you can quickly break it by adding an extra row to the 'Schedule' table with "8" as the value in the A column and the formula in B:
A | B
---------
3 | d
5 | a, c
7 | b
8 | N/A
The "8" throws an error since it isn't found in the 'Core Data'.
Conversely, on my original spreadsheet, When I tried the formula in a cell which did correspond to a noted deadline, it worked.
I found the solution here is to add an IFERROR function to the formula to deal with this.
So a formula that works for this is:
=JOIN(", ", IFERROR(FILTER('Core Data'!A:A, 'Core Data'!B:B=A5)))
One does not use the second IFERROR argument as advised in Google's own helpsheet. I tried putting in an empty array at first ({}) but this threw a different error. It seems if you miss the argument out, the JOIN knows it has nothing to work with and the cell ends up with a nice blank value.

Resources