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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Niels_T
Post Patron
Post Patron

Power Query M Language - Adding 5 years to end of the current year

Hello,

 

I would like to add 5 more years to this M Language function.

= Date.EndOfYear(DateTime.Date(DateTime.FixedLocalNow()))

 

This one returns only the end of the current year.

 

How can I do this?

 

 

1 ACCEPTED SOLUTION

Hello,

 

Thank you for trying to help me.

 

After playing around for a long time I finaly found it.

 

I basically did the following:

= Date.AddYears(Date.EndOfYear(DateTime.Date(DateTime.FixedLocalNow())), 5)

 

This extended the end date by 5 years.

View solution in original post

7 REPLIES 7
Thejeswar
Resident Rockstar
Resident Rockstar

Hi @Niels_T ,

You can use the AddYears function.. See below the M Query for the same

#"Added Custom" = Table.AddColumn(#"previous_step", "5_Years_later", each Date.AddYears([Finishtime], 5))

 

PFB sample screenshot

Thejeswar_0-1645183884850.png

 

I'm sorry. I wasn't very clear.

 

I just want to have the original dates but the column needs to be longer by adding 5 more extra years instead of stopping at the current year.

Hi,

Can you share a sample of how you want your output to look like

I would like to have the data as followed:

 

DateDate (5 years extended)
01/01/202101/01/2021
02/01/202102/01/2021
03/01/202103/01/2021
......
 01/01/2025
 01/01/2025

 

Niels_T_0-1645187426879.png

 

 

As you can see dates need to be exactly the same. Just the column needs to be extended by 5 years more.

Hi @Niels_T ,

 

Please try the following formula:

 

let
    Source = Duration.TotalDays( Date.AddYears( Date.EndOfYear( DateTime.Date( DateTime.FixedLocalNow() ) ), 5 ) - DateTime.Date( DateTime.FixedLocalNow() ) ),
    #"List Dates" = List.Dates( #date(2021,1,1), Source, #duration(1,0,0,0) ),
    #"Converted to Table" = Table.FromList(#"List Dates", Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
    #"Converted to Table"

vkkfmsft_0-1645521607080.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hello,

 

Thank you for trying to help me.

 

After playing around for a long time I finaly found it.

 

I basically did the following:

= Date.AddYears(Date.EndOfYear(DateTime.Date(DateTime.FixedLocalNow())), 5)

 

This extended the end date by 5 years.

Hi Niels.  This worked perfectly for me, I really appreciate it!!!  Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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