Google Sheets: IF and Date formula not working - google-sheets

I'm calculating annual holiday accrual.
All holiday resets at the start of the calendar year.
If a staff member started after 01.01.2017 they will have a lower holiday entitlement for the year.
I'm trying to create a formula which says:
If this cell's date is after 01.01.2017 return that cells date. Otherwise, set it at 01.01.2017.
(so basically, I don't care when they started if it was before 01 Jan 2017 because all my following calculations will be based off the first day of the year)
Here it is:
=if(T21<date(1,1,2017),T21,"01/01/2017")
No matter what is in the cell, it is returning 01/01/2017.If I change the < to > it returns cell T21 in all cases.
Any ideas?
Thanks

You have the DATE() values mixed up. Try:
=if(T21<date(2017,1,1),T21,"01/01/2017")
DATE() is year, month, day
Also, you may want to use DATEVALUE() on the FALSE value to force the returned item to a date:
=if(T21<date(2017,1,1),T21,DATEVALUE("01/01/2017"))

"01.01.2017" is not a valid date in Google docs. You need to change . to /.
=DATEVALUE(SUBSTITUTE(T21,".","/"))
=IF(DATEVALUE(SUBSTITUTE(T21,".","/"))<DATEVALUE(date(2017,1,1)),T21,"01/01/2017")

Related

I am trying to calculate the fiscal year months ending with the last month for the current fiscal year in Tableau

I have created a parameter in Tableau called Fiscal Start Month and it represents an integer for the beginning month of my fiscal year which is May. The integer is set to -8. I created this calculation to show the dates in the relative time frame which should be May 1 - December 31, 2022. The "DOS" is a date field for Date of Service, and I created another calculated field called "date" for today's date:
IF [DOS] >=DATE(DATEADD('month',[Fiscal Year Start],[Date])) AND [DOS] <=DATE(DATEADD('month',1,DATETRUNC('month',[Date])))
THEN 'Show'
ELSE 'Hide'
END
When I filter my data I am getting items from May 5th and it is hiding May 1 - 4. Can someone help me understand why this calculation might not bring in the appropriate dates?
I tried the formula above and this is what I am expecting
enter image description here

how to change cell reference value on weekly basis or daily basis automatically without manually changing the cell reference

I have a date range on the basis of Week1, week2,week3 and so on, This wwekly range is starting from 2022 week1 to 2023 week52. Now I want to have a variable or cell reference which need to change every week. For example right now I am in week 25 so cell reference need to be 25 week then next week is week 26 then cell reference need to change automatically into week 26.
try:
=ISOWEEKNUM(TODAY())&" Week"
this for get data from
sheet: week
column: A
row: weeknumber (auto)
=indirect( "week!" & "A" & ISOWEEKNUM(NOW()) )

How to auto create a Month calendar in google sheets. Where first day of the month start in the colum of the (name)day

I want to create a calendar like in the second image. But I can not figure out how to start the first column is a monday. So I fill it by 'hand' like in the first image.
I tried to create it automatic. Starting with the first day of the month and add one day the next columns like in the second picture:
How I want it to look like:
How it is currently looking:
Google sheets example
I was solving the same problem for my bussiness, and I think I got the answer.
Your first task is to determine the first "calendar monday" of the month.
First, build the first day of the corresponding month:
[B2] =DATE(YEAR(A1); MONTH(A1); 1)
Then, get the WEEKDAY of the corresponding first day. The second argument represents what day your week starts with:
If type is 1, days are counted from Sunday and the value of Sunday is 1, therefore the value of Saturday is 7.
If type is 2, days are counted from Monday and the value of Monday is 1, therefore the value of Sunday is 7.
If type is 3, days are counted from Monday and the value of Monday is 0, therefore the value of Sunday is 6.
In my case, we count the week starting from Monday. This means when the first day of the month lands on Monday, the return value will be 0.
[C2] =WEEKDAY(B2; 3)
The number you get represents how many days you need to substract from the initial date to get the first "calendar monday" of the month:
[D2] =B2 - C2
This date is what you are looking for. The final formula:
[A3] =DATE(YEAR(A1); MONTH(A1); 1) - WEEKDAY(DATE(YEAR(A1); MONTH(A1); 1); 3)
The rest of the days, simply add 1 to each preceding date.
[A4] =A3 + 1
[A5] =A4 + 1
And so on.
Secondly, set the Number Format on the calendar cells to just show the day.
Format -> Number -> More Formats -> More Date and Time Formats.
Select just the day from the drop down.
Finally, use conditional formatting to "hide" the values that don't match the initial date
Use a custom formula for the formatting, as follows:
=MONTH(A3) <> MONTH(A1)
Apply to the calendar range. This will format dates that don't belong to the current date, so make sure to paint that white.
And that's about it. Good luck!

How to check if today's month date is greater than or less than a decimal number?

I have a column with month day numbers, so 20 means the 20th of the month.
I want to know how to check if a value in this column, say 20 is more than or less than today's month day.
I would use conditional formatting to color the cell in red if that day had not passed already.
What I tried to do was set a cell with today's date:
=TODAY()
Then based on this calculate if the month day was less than or greater by using this:
=DATEDIF(F2, "MD")
I was hoping this wold return a number which I could then do a compare with but this is wrong and I am not sure if what I want to do is even possible.
I have read through the documentation and Stackoverflow but I cannot find any close examples.
Thank you.
If you want to check the day of the month you need to extract exactly that.
If your date is in Cell A1 and your threshold (20) in A2 the conditional formatting formula to check if the date has not passed yet would then go:
=DAY(A1) < A2

Roll-Forward Date Patterns in Excel

Using Excel 2010, I need to take an existing date in 2015 (i.e. 2/11/15), and calculate the same date position in the next year. In other words, whatever is the specific date pattern with the existing date, I'm looking for a formula that will help me calculate the exact same date pattern. If 2/11/15 is the second Wednesday in February of 2015, I need a formula to help me calculate (using the existing date) the second Wednesday of February in 2016.
#Jeeped, thanks for your reply. You're correct - there's many "conditions" to account for. Two colleagues helped-out with the following:
=IF('Data (Reference)'!C14>"", CONCATENATE(TEXT('Data (Reference)'!C14, "MM"),"/", TEXT(7-(WEEKDAY(CONCATENATE(TEXT('Data (Reference)'!C14,"MM"),"/", Input!$C$2))-1)-7+TEXT(WEEKDAY('Data (Reference)'!C14), "DD")+(CEILING(TEXT('Data (Reference)'!C14, "DD")/7, 1)-(IF(TEXT(WEEKDAY('Data (Reference)'!C14), "DD")
We had to consider wherever the existing date fell, and dynamically identify the pattern and/or condition and re-apply it in the roll-forward sequence.

Resources