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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Create dynamic Calendar based on todays date (M-query)

Hi 

Just in case someone else needs to create a calendar that is x months before current date and x months after, her is M-query code to create Calendar table.

 

Create Blank Query and open Advanced Query - insert the code below instead of the default code.

 

You can change the StartDate and EndDate as you please, here it is 1 month before and 12 month after:

 

let
Source = List.Dates(StartDate, DurationDays, #duration(1, 0, 0, 0)),
StartDate = DateTime.Date(Date.StartOfMonth(Date.AddMonths(DateTime.LocalNow(),-1))),
EndDate = DateTime.Date(Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow(),12))),
DurationDays = Duration.Days(EndDate - StartDate),
ToTable = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(ToTable,{{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}})
in
#"Changed Type"

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi

 

It is only for sharing.  I have tagged it as such.

 

rgds

Kirsten

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

 

Is this a sharing or a question?

 

If this is a question, please share your desired output so that we could help further on it.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

It is only for sharing.  I have tagged it as such.

 

rgds

Kirsten

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 MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.