Using If Statement to assign data to a year

VBAN0oB

New Member
Joined
Oct 19, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
I am trying to use an IF statement to assign losses to a certain year; however since the policy years differ from client to client it is not like trying to assign based on a fiscal year. So I have my "Effective Date" in cell N6 and in column A I am using the following formula:

=IF(ISBLANK(C2),"",IF(C2<DATE(YEAR($N$6),MONTH($N$6),DAY($N$6)),YEAR(C2)-1&"/"&RIGHT(YEAR(C2),4),YEAR(C2)&"/"&RIGHT(YEAR($N$6)+1,4)))

It appears to be working, until I get to row 16, 17 & 18 (on attached) where my date of loss is late December (the term in column A should be 2023/2024 but instead it is showing 2022/2023). My ask of someone with more brain power than I have is the following:

1. What am I doing wrong in my formula (If my Effective Date in N6 was 12/08/2023 the terms in column A would be correct)
2. How do I make it where column A shows the years as YY/YY instead of YYYY/YYYY - My OCD can't handle it.
 

Attachments

  • Capture.PNG
    Capture.PNG
    64.9 KB · Views: 19

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
1. The date in N6 is year 2024 in your image. The December dates in column C are year 2023. So the formula appears to be correct. If you change the year in N6 to 2023, you should get the correct 2023/2024 for December.

2.
Excel Formula:
=IF(ISBLANK(C2),"",IF(C2<$N$6,TEXT(EDATE(C2,-12),"YY/")&TEXT(C2,"YY"),TEXT(C2,"YY/")&TEXT(EDATE(C2,12),"YY")))
 
Upvote 0
So the formula appears to be correct. If you change the year in N6 to 2023, you should get the correct 2023/2024 for December.
Changing the N6 date to 2023 does fix those 2023/2024 dates but row 20 then fails as far as I can see.


Assuming that you do not have dates going back to last century, would this also work for you?
Excel Formula:
=IF(C2="","",LET(yr,RIGHT(YEAR(C2)-(C2<$N$6),2),yr&"/"&yr+1))

If you do have dates going back to cover the 1999/2000 year then
Excel Formula:
=IF(C2="","",LET(yr,RIGHT(YEAR(C2)-(C2<$N$6),2),yr&"/"&RIGHT(yr+1,2)))
 
Last edited:
Upvote 0
1. The date in N6 is year 2024 in your image. The December dates in column C are year 2023. So the formula appears to be correct. If you change the year in N6 to 2023, you should get the correct 2023/2024 for December.

2.
Excel Formula:
=IF(ISBLANK(C2),"",IF(C2<$N$6,TEXT(EDATE(C2,-12),"YY/")&TEXT(C2,"YY"),TEXT(C2,"YY/")&TEXT(EDATE(C2,12),"YY")))
N6 is stating that my policy began 12/08/2024; so the loss that occurred 12/28/2023 would have occurred during the 12/08/2023-12/08/2024 term. However, column A row 16, 17 & 17 are showing 22/23 instead of 23/24.
 
Upvote 0
Changing the N6 date to 2023 does fix those 2023/2024 dates but row 20 then fails as far as I can see.


Assuming that you do not have dates going back to last century, would this also work for you?
Excel Formula:
=IF(C2="","",LET(yr,RIGHT(YEAR(C2)-(C2<$N$6),2),yr&"/"&yr+1))

If you do have dates going back to cover the 1999/2000 year then
Excel Formula:
=IF(C2="","",LET(yr,RIGHT(YEAR(C2)-(C2<$N$6),2),yr&"/"&RIGHT(yr+1,2)))
Thank you for your help, this got my years to show XX/XX instead of 4 digits and for that I am thankful. However, it is still not showing the right terms for rows 16, 17 & 18. Those three cells should result in 23/24 and it is showing 22/23.
 
Upvote 0
This is a fair bit longer but give it a try:
Excel Formula:
=LET(YrsOffset,IF($N$6>=C2,-DATEDIF(C2,$N$6,"y"),DATEDIF($N$6,C2-1,"y")+1),
EndYear,YEAR($N$6)+YrsOffset,
StartYear,EndYear-1,
txtPeriod,RIGHT(StartYear,2)&"/"&RIGHT(EndYear,2),
txtPeriod)
 
Upvote 0
However, it is still not showing the right terms for rows 16, 17 & 18.
Is this any better?

25 01 25.xlsm
ACN
1
221/2228-Jan-22
321/2211-Apr-22
421/2218-May-22
521/2214-Jun-22
621/2229-Jul-2208-Dec-24
721/2206-Aug-22
821/2208-Aug-22
921/2230-Sep-22
1021/2228-Nov-22
1121/2222-Nov-22
1221/2206-Jul-22
1322/2330-Mar-23
1422/2330-Mar-23
1522/2324-Jun-23
1623/2428-Dec-23
1723/2428-Dec-23
1823/2428-Dec-23
1922/2303-Feb-23
2023/2422-Jan-24
2120/2102-Mar-21
2220/2126-May-21
Year
Cell Formulas
RangeFormula
A2:A22A2=IF(C2="","",LET(y,RIGHT(YEAR(C2)-(DATE(YEAR(N$6),MONTH(C2),DAY(C2))<N$6),2),y&"/"&y+1))
 
Upvote 0
Solution
@VBAN0oB If the Column C date is on an anniversary date, your original formula would put it in the earlier year.
If that was correct just change Peter's formula to be <=N$6
 
Upvote 0
Is this any better?

=IF(C2="","",LET(y,RIGHT(YEAR(C2)-(DATE(YEAR(N$6),MONTH(C2),DAY(C2))<N$6),2),y&"/"&y+1))

Peter, this works perfectly!! Thank you so very much for not giving up on me when I couldn't get it right the first time. I sincerely appreciate your willingness to assist me with this problem.
 
Upvote 0

Forum statistics

Threads
1,226,017
Messages
6,188,441
Members
453,474
Latest member
th9r

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top