Change the date to fiscal year - excel

I want to write a function in Excel to change the date. The logic is like this: if the month is (Jan, Feb or March) the result show me one year past (-1 year) and if the month is (April to -December) the result show the current year (which year the date shows).
example: if date is 02,Jan,2012 the result show me 2011 else show me 2012.

=IF(MONTH(G3) >=4, YEAR(G3), YEAR(G3) - 1) where G3 is the date to test, is one way.

Please try:
=IF(OR(MONTH(A1)=1,MONTH(A1)=2,MONTH(A1)=3),2011,2012)

With 02-Jan-2012 in A1 try,
=YEAR(A1)-(MONTH(A1)<4)
For a full date use one of these,
=DATE(YEAR(A1)-(MONTH(A1)<4), MONTH(A1), DAY(A1))
=EDATE(A1, -(MONTH(A1)<4)*12)

To extract fiscal year use:
=YEAR(A1) + IF(MONTH(A1)>=4,1,0)
I think in your case you would need:
=YEAR(A1) - IF(MONTH(A1)>=4,0,1)
If the months is before 4th month then subtract 1 year, else keep the same year. I wouldn't convert it to a full date DD/MM/YYYY with a 1 year subtracted, to avoid confusion keep it as year only YYYY.

Already plenty of answers, but thought I'd throw another one up:
=YEAR(DATE(YEAR(A1),MONTH(A1)-3,DAY(A1)))

Related

how to calculate the date from the year, week-of-year and day-of-week in EXCEL?

I have the Year, Week-of-Year and Day-of-the-Week as follows:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
and I would like to estimate the Date as dd.mm.yyyy, which is highlighted in yellow as it shows in the EXCEL picture.
I tried many formulas, but I am sure there might be an easy one.
I think you are counting the weeks starting from zero because for 9/1/2022 (YYYY/MM/DD format) the corresponding week is 36 as per the result of function WEEKNUM(DATE(2022,9,1)). In order to use the logic to multiply the number of weeks by 7. You need to use as a reference the first day of the year, if it was a Sunday, if not then go back to the previous Sunday, so you can count the entire week. Bottom line use as a reference date, the Sunday of the first week of the year, not the first day of the year (YYYY/1/1)
Here is the approach we use in cell E2:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1))
We use the LET function to avoid repeating the same calculation. The following expression finds the previous Sunday if the first day of the year (fDay) was not a Sunday:
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2))
The XLOOKUP function is used to get the numeric representation of the weekday and use the TEXT function to generate the weekdays in a long format. Since we count the entire week, if the weekday is a Sunday (column C in my screenshot), then we don't need to add any day to our reference date, that is why we use seq-1.
Here is the output for several sample data. Assuming the week count starts with zero, if not the formula needs to be adjusted as also the input data.
Notice that the year 2021 started on a Friday, so if we want to find a day for the first week (0) before Friday it will return a date from the previous year. Like in the case of Monday. If you want an error message instead, then the formula can be modified as follow:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
result, fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1),
IF(YEAR(result) <> y, "ERROR: Date from previous year", result))
I found the solution:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
=DATE (A2,1,3)-WEEKDAY(DATE(A2,1,3)) + 7 * B2 + C2 - 6
I found this solution, but you need to do further testing if it really works.
I calculate month from week: =+MONTH(DATE(YEAR(A2);1;1)+B2*7-1)
I calculate week day number from week day name: =MATCH(D2;{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"};0)
And then make date using: =DATE(A2;C2;E2)

Comparing dates in Excel

I'm trying to compare date in excel to return a value.
I want to see...
if date of birth + today() is less than DATE(2021,9,1) years then output 6
if date of birth + today() is less than DATE(2021,9,1) years then output 5
if date of birth + today() is less than DATE(2021,9,1) years then output 4
if date of birth + today() is less than DATE(2021,9,1) years then output 3
This is for a school project. I'm struggling to understand the date concept.
Can someone point me in the right direction?
Thanx for reading,
Sam
This should work, imagining that cell A1 contains the date of birth:
=IF((A1 + today()) < DATE(2021,9,1), 6)
=IF((A1 + today()) < DATE(2021,9,1), 5)
=IF((A1 + today()) < DATE(2021,9,1), 4)
=IF((A1 + today()) < DATE(2021,9,1), 3)
After going home and sleeping on it, I think I figured it out. I wanted my date to be static and check against pupil date of births to determine their age for a particular year. I already have a version of this which is dynamic and updates itself when the sheet is loaded. Here is what I did, where E3 is equal to a pupils date of birth...
=IF(E3="","",
IF(DATEDIF(E3,DATE(2021,9,1),"Y")+1>=11,6,
IF(DATEDIF(E3,DATE(2021,9,1),"Y")+1>=10,5,
IF(DATEDIF(E3,DATE(2021,9,1),"Y")+1>=9,4,
IF(DATEDIF(E3,DATE(2021,9,1),"Y")+1>=8,3,
"")))))
If there is an easier way to accomplish this I would relish feedback.
Thanx again to those of you who replied,
Sam
This is my dynamic version
=IF(E3="","",MAX(0,DATEDIF(DATE(YEAR(E3+122),9,1),NOW(),"Y" )-4))
This calculates age
=IF(E3="","",
DATEDIF(E3,TODAY(),"Y") & "." &
DATEDIF(E3,TODAY(),"YM") & "." &
DATEDIF(E3,TODAY(),"MD")
)
In Excel, a date is stored as a number of days since 1/1/1900 (or 1904, not very important), you can subtract date2-date1 and that will return the number of days between the 2 dates.
With that logic, a simple formula to get your age from your birth date stored in E3 would be:
=INT((TODAY()-E3)/365)
Just for fun, enter a date in a cell, then Clear Formats. You will see the number of days.

How to get week start and week end in excel for given month only

As I was new to excel, I am working on a use case where I want to get week start and week end dates of a given month,
I am using following formulae which is giving me next month date followed by weekend.
=A7+(6-WEEKDAY(A7,2)+1)
Week Start Week End
7/1/18 7/1/18
7/2/18 7/8/18
7/9/18 7/15/18
7/16/18 7/22/18
7/23/18 7/29/18
7/30/18 8/5/18
How can I modify or have a new formulae which gives me month end date, if my weekend is on next month
Expected output should be
Week Start Week End
7/1/18 7/1/18
7/2/18 7/8/18
7/9/18 7/15/18
7/16/18 7/22/18
7/23/18 7/29/18
7/30/18 7/31/18
For month like Feb as it is unable to caluculate the formula it should return 0
Week Start Week End
2/1/18 2/4/18
2/5/18 2/11/18
2/12/18 2/18/18
2/19/18 2/25/18
2/26/18 2/28/18
1/0/00 1/1/00
You just need to wrap the result of your original formula in MIN and compare it to EOMONTH.
=MIN(A7+(6-WEEKDAY(A7,2)+1), EOMONTH(A7, 0))
As far as Feb goes, you need to compare te current value with the one either above or below to determine whether month(date)<>month(date+7) and you have not shown enough of how your data structure transcends months to do that.

How do I write an Excel formula to compare year-to-date to prior years & also account for leap years?

I’m trying to compare a measure as of today through the same day and month for the prior 4 years (e.g. through June 6 of 2016, 2015, 2014, etc.).
For each year, I decided to count the number of days since the beginning of the year, and sum my values through that number of days for each year.
To identify whether a date should be included in the year to date comparison, I used the formula where my date is in cell A1:
=IF((A1-DATE(YEAR(A1),1,1)+1)<=(TODAY()-DATE(YEAR(TODAY()),1,1)+1),1,0)
I’m looking for a way around the issue of the extra day added to leap years. In other words, after February 28th, the day count will always be off by one in a leap year, and trying to use Februrary 29th in a non-leap year will return an error.
I’d like to adjust this formula, but I’m open to using a different function & formula if it gets me the right results.
you can check any information about February, 29th. If an error occurs, you know its no leap year. Catch that error with =IFERROR(;).
Assuming a table structure like this:
A:Date | B:Value
----------------------
01/01/2016 | 0
01/01/2015 | 1
01/01/2014 | 2
01/01/2013 | 3
01/01/2012 | 4
Formula
To - for example - calculate the average of the previous four (excluding the current) years on January 1st (today is 01/01/2016):
=SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
(B:B)
) / (
SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
1
)
)
Result
For the above example, the result is 2.5
Explanation
To select only those rows representing the same month and day:
(MONTH(A:A)=MONTH(compare))*(DAY(A:A)=DAY(compare))
To select only those values from the previous 4 years (excluding the current):
(YEAR(A:A)>YEAR(compare)-5)*(YEAR(A:A)<YEAR(compare))*
The actual values we are interested in:
(B:B)
Divide by 4 for the average over the last four years. This assumes there is no missing data which might be an issue. You could use another SUMPRODUCT (replace B:B with 1) to count the number of resulting rows and divide by that number to handles this case. This seems to be rather slow, but it works.
Note
For performance reason you should not use A:A (a full column) in the formula, just use the actual range you need, which will likely be much faster.

Excel work out fiscal year

The fiscal year starts on July 1 and ends on June 30th.
I need to calculate the fiscal year + month in the following format
26/05/2006 2005011
26/05/2006 2005011
09/06/2006 2005012
15/06/2006 2005012
My current formula is below.
=YEAR(A2)&"0"&MOD(MONTH(A2)-7,12)+1
The problem is that the formula populates the current year and not based on the fiscal year.
25/05/2006 2006011
26/05/2006 2006011
26/05/2006 2006011
09/06/2006 2006012
15/06/2006 2006012
Use EDATE()
=YEAR(EDATE(A1,-6)) & "0" & TEXT(MONTH(EDATE(A1,-6)),"00")
you need to do a check for the current date to see if it is before or after your breakpoint of june 30/july 1st.
=IF(A2<=Date(year(A2),6,30),Year(A2)-1,Year(A2))&"0"&MOD(MONTH(A2)-7,12)+1
So after you determine if you need to subtract 1 from your year or not, tack on the rest of your formula.

Resources