Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
abfdjuk
Helper I
Helper I

Code for custom year shows the wrong result

Hi All

 

I have created a simple code to say if the month is september or earlier and the date is 14th or earlier then show Year -1 and if greater than show year. BUT the year shows correctly for dates before but doesn't seem to work for dates after. Where am I going wrong?

 

TEST Year =
VAR FY =
IF (MONTH( ( 'Date'[Date] ) <= 9 && DAY ( 'Date'[Date] ) <=14),
VALUE ( FORMAT ( 'Date'[Date], "YY" ) )-1 ,
VALUE ( FORMAT ( 'Date'[Date], "YY" ) ))RETURN
CONCATENATE ( "", FY )
1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

I'm not too sure of the logic here. What you are saying is that 13/september/2022 is FY 2021, but the 20/august/2022 is FY 2022?

If so , try:

 

 

FY =
IF (
    AND ( MONTH ( fTable[Date] ) < 10, DAY ( fTable[Date] ) < 15 ),
    YEAR ( fTable[Date] ) - 1 & " FY",
    YEAR ( fTable[Date] ) & " FY"
)

 

 

result.jpg

 

If the cut-off date is the 14 september (so dates before are the previous year and dates after are the current year, then try:

FY 14 sep = 
VAR _Date = DATE(YEAR('Date'[Date]), 9, 15)
RETURN
IF (
    'Date'[Date] < _Date,
    YEAR ( 'Date'[Date] ) - 1 & " FY",
    YEAR ( 'Date'[Date] ) & " FY"
)

res 1.jpg

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

4 REPLIES 4
PaulDBrown
Community Champion
Community Champion

I'm not too sure of the logic here. What you are saying is that 13/september/2022 is FY 2021, but the 20/august/2022 is FY 2022?

If so , try:

 

 

FY =
IF (
    AND ( MONTH ( fTable[Date] ) < 10, DAY ( fTable[Date] ) < 15 ),
    YEAR ( fTable[Date] ) - 1 & " FY",
    YEAR ( fTable[Date] ) & " FY"
)

 

 

result.jpg

 

If the cut-off date is the 14 september (so dates before are the previous year and dates after are the current year, then try:

FY 14 sep = 
VAR _Date = DATE(YEAR('Date'[Date]), 9, 15)
RETURN
IF (
    'Date'[Date] < _Date,
    YEAR ( 'Date'[Date] ) - 1 & " FY",
    YEAR ( 'Date'[Date] ) & " FY"
)

res 1.jpg

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Great thanks. The odd start dates correlates to the agricultural year in the UK.

How do I display the year as just the two last numbers?

Use the RIGHT functio:

FY Short = 
IF (
    AND ( MONTH ( 'Date'[Date] ) < 10, DAY ( 'Date'[Date] ) < 15 ),
    RIGHT(YEAR ( 'Date'[Date] ) - 1, 2) & " FY",
    RIGHT(YEAR ( 'Date'[Date] ), 2) & " FY"
)

short.jpg

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors