Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Create dynamic list of dates

Hello,

I have the following step in Power Query and it creates a list of dates and i would like to make it dynamic so that it only lists dates since previous 2 months until the end of the current month. Today is 20 April 2022 so the list of dates should be from 1 February 2022 until 30 April 2022. Any help is much appreciated!

 

= List.Buffer(List.Dates(#date(2022,2,1),365,#duration(1,0,0,0)))

 

Here is some related code for a better idea but i couldn't get it to work by just replacing, since it uses a List.Buffer and i would like to keep the format as close to the original as possible without breaking the subsequent steps in Power Query.

 

Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),-2)),  
Date.EndOfMonth(Date.From(DateTime.LocalNow())))

 

  • Here you are...

     List.Dates(Date.AddMonths(Date.StartOfMonth(Date.From(DateTime.FixedLocalNow())),-2), Number.From(Date.EndOfMonth(DateTime.FixedLocalNow()))- Number.From(Date.AddMonths(Date.StartOfMonth(DateTime.FixedLocalNow()),-2)) ,#duration(1,0,0,0))

1 Reply

  • Here you are...

     List.Dates(Date.AddMonths(Date.StartOfMonth(Date.From(DateTime.FixedLocalNow())),-2), Number.From(Date.EndOfMonth(DateTime.FixedLocalNow()))- Number.From(Date.AddMonths(Date.StartOfMonth(DateTime.FixedLocalNow()),-2)) ,#duration(1,0,0,0))