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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Syndicate_Admin
Administrator
Administrator

Add years to a date column.

Good. I need to add a certain number of years to a column of dates. I have found solution with M language in query or through queries. I would like to know the solution through DAX since I want to do it through a measure including a conditional. I mean:

-I have a column of dates.

-If the date is greater than 2023 I add 5 years to the date.

-If the date is less than 2023 I add 2 years to the date. I have tried with DATEADD but I am not able to. What do you recommend?

Thank you. Best regards.

1 ACCEPTED SOLUTION

pls try this

Measure = 
VAR _Curentdate = SELECTEDVALUE('Table'[Date])
VAR _offset1 = MONTH(_Curentdate) *5 *12
VAR _offset2 = MONTH(_Curentdate)*2 *12
RETURN

SWITCH( TRUE(),
          _Curentdate>= DATE(2023,1,1), EDATE(_Curentdate,_offset1), EDATE(_Curentdate,_offset2))

Screenshot_4.png

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Try this measure

Measure = if(year(min(Data[Date]))<2023,edate(min(Data[Date]),2),edate(min(Data[Date]),5))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Syndicate_Admin
Administrator
Administrator

Good

Thanks for the reply. I have tried what it proposes and it works for me. In fact, I have accepted it as a solution. The problem is that I always try to solve through measures and avoid calculated columns as much as possible. I am trying to implement the same solution with a measure but I am not able. Could you tell me how I can apply the same solution to a measure? Thank you so much. Best regards.

pls try this

Measure = 
VAR _Curentdate = SELECTEDVALUE('Table'[Date])
VAR _offset1 = MONTH(_Curentdate) *5 *12
VAR _offset2 = MONTH(_Curentdate)*2 *12
RETURN

SWITCH( TRUE(),
          _Curentdate>= DATE(2023,1,1), EDATE(_Curentdate,_offset1), EDATE(_Curentdate,_offset2))

Screenshot_4.png

Ahmedx
Super User
Super User

pls try this

Column = 

VAR _offset1 = MONTH([Date]) *5 *12
VAR _offset2 = MONTH([Date]) *2 *12
RETURN

SWITCH( TRUE(),
            [Date]>= DATE(2023,1,1), EDATE([Date],_offset1), EDATE([Date],_offset2))

Screenshot_1.png

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.