google spreadsheets: Compare date with dates in a cell range - google-sheets

I have a date in cell B1 and list of Dates in A1:A100.
I would like to get for B1 the cell in A1:A100 where the date has the smallest difference in time.
As you can see in the example, the closest Date to B1 from A1:A100 is in cell A2.
A B C
1 15.4.2011 03.3.2011 A2
2 01.3.2011
3 11.7.2011
4 09.2.2011

To get the dates which are nearest to the date in cell B1, try the following formula in some free cell:
=arrayformula(filter(A:A,abs(A:A-B1)=min(abs(A:A-B1))))
And to get the row number in which the nearest date is, try the following formula:
=arrayformula(match(filter(A:A,abs(A:A-B1)=min(abs(A:A-B1))),A:A,0))
And finally try the following formula for your desired result:
=arrayformula(address(match(filter(A:A,abs(A:A-B1)=min(abs(A:A-B1))),A:A,0),1,4,true))

Related

Test cell value if is in the interval with arrayformula

I want to use arrayformula on the top of my row to spam its calculations in the column. In my sheet I have to test if the value on the cell of column F (Teste) is on the interval (for instance if cell F18 = 2 < 3 is TRUE). Here's the code on the cell G1 I've written:
=ARRAYFORMULA(IF(ROW(G:G)=1;"Classe";IF(AND(F2:F>0;F2:F<3);"ok";1)))
But instead of computing the AND(F2:F>0;F2:F<3) it just returns FALSE. So the question is: how do I write such formula that takes a value on a cell and compares if it is on the interval I want and then show "ok"? Thank you for the help!
Image of my sheet:
My spreadsheet image
use:
=ARRAYFORMULA(IF(ROW(G:G)=1; "Classe"; IF((F2:F>0)*(F2:F<3); "ok"; 1)))

Google Sheet Conditional Formatting Based on Date

So I want to have a cell change red if the date in that cell is 2 months from todays date. (contract end date is 17th July, 1 month from now, cell is red)
I have put:
=Today() in cell Y3
=($Y$3-$B3) in cell Z3 and dragged it down, as all dates are different
And then in Column B:B where the dates are I condition formatted - custom formula is and put =AND(($Z3>0), ($Z3<60))
Not working :(
You can just use conditional formatting on the columnB:B.
Set the custom formula to:
=AND(B1 <> "", ROW(B1) >= 3, EDATE(TODAY(), 2) > B1)
ROW(B1) >= 3 - assuming your data starts from the 3rd row.

Obtain first date in column after reference date

In cell B1, I have =today() for today's date and then in the cells below (B2:B100), What I'm trying to do is to compare the date in cell B1 (today's date) and to find the next date that appear in cells B2:B100 AFTER this date and then copy this into A2.
So, in effect, in cell A2, I want a function to look up the next date in cells B2:B100 that is the nearest one AFTER B1 and then copy this into A2. I know this is a formula to add in A2 but just unsure what formula to use.
I've tried this in cell A2,
=MIN(IF(B2:B100>B1, B2:B100))
but it didn't work.
"Other things being equal", the formula is correct but should be entered in the array version (eg with Ctrl+Shift+Enter):
=ArrayFormula(MIN(IF(B2:B100>today(),B2:B100)))
Building the function from B1 into the formula is optional.

Colour a cell based on the length of time between that date cell and another date cell

This query is in relation to Google Sheets.
If the date in B1 is 10 days older than the date in A1, then B1 is shaded red.
If the date in B1 is within 10 days of the date in A1, then B1 is shaded green.
Does anyone know how I can do this please?
We hope to use this as follows:
Record the date we submit a product.
Record a date to show we have detailed the product as suitable.
(We want this to be within 10 days of us initially submitting the product.)
Therefore we submit a product on the date in A1
We then detail the product as suitable and record this date in B1.
If we have done this within 10 days, B1 should be green. If not, it should be red. This will help us deal with delays.
Does anyone know how I can do this within Google Sheets please?
You have to use Format > Conditional Formatting for the column B, defining the range from the second row:
B2:B1000
You have to set the range this way because the formula is always evaluating in its top left corner first. So you can get the past date from row 1 and formatting the cell in row 2.
You should format your cells with custom formula like:
=DATEDIF(A1,A2,"D")>10
Your B column by default can be green.
You can check my demo sheet for this problem here.
DATEDIF:
https://support.google.com/docs/answer/6055612?hl=en
Conditional Formatting:
https://support.google.com/docs/answer/78413

Fill column with maximum/last value from another column

How can I get the result as in example with ARRAYFORMULA up to last filled cell A?
I can do it with formula in cell C1 =MAX(B$1:B1) but in that case have to copy the formula in each cell in turn.
In C2 try:
=ArrayFormula(if(row(A2:A) <= max(if(not(isblank(A2:A)), row(A2:A))),vlookup(row(A2:A),filter({row(A2:A),B2:B},len(B2:B)),2),))
See this spreadsheet for an example.

Resources