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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Victormar
Helper V
Helper V

Year calculation for leap years

Hello, community

 

I have a situation where I have contracted dates for vehicles, and I need to calculate the renovation date, which is after 6 months and after one year. The thing is that I have some vehicles with starting contracts on the 1st of March, therefore when I do a formula where I add a year to it, it can happen that the result is the 2nd (If I am not wrong, Power BI just adds 365 days to it, and I am guessing for shortened February years that is a potential problem).

 

This is my formula:

c_AnniversaryDate =
VAR six_months =
    DATE ( YEAR ( [Current year start date] ), MONTH ( DIM_Chassis[CONTRACT_START_DATE] ) + 6, DAY ( DIM_Chassis[CONTRACT_START_DATE] ) )
VAR twelve_months =
    DATE ( YEAR ( [Current year start date] ) + 1, MONTH ( DIM_Chassis[CONTRACT_START_DATE] ), DAY ( DIM_Chassis[CONTRACT_START_DATE] ) )
RETURN
    IF (
        [Current year start date] < TODAY ()
            && TODAY () > six_months,
        twelve_months,
        six_months
    )

 

Does anybody know how to solve that scenario?

 

Thanks in advance for your time 🙂

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Victormar 

 

Instead of adding a 1 to the year or 6 to the month, why not just use EDATE?  EDATE ( DATE (2024, 3, 1), 18 ) is DATE (2025, 9, 1) which is 18 months after the original date. Or if you want the date 18 months prior, just use -18.
March 1, 2024 becomes





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
Victormar
Helper V
Helper V

thanks! that worked really good!

danextian
Super User
Super User

Hi @Victormar 

 

Instead of adding a 1 to the year or 6 to the month, why not just use EDATE?  EDATE ( DATE (2024, 3, 1), 18 ) is DATE (2025, 9, 1) which is 18 months after the original date. Or if you want the date 18 months prior, just use -18.
March 1, 2024 becomes





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors