list all dates from previous month

Hi,

I'm trying to create a column in Power Query Excel that lists all dates from the previous month.

Googling and loosing.

Any help much appreciated.

Posted Jun 22, 2022, 3:09 PM UTC

27
mOnion•

Just Google a calendar table and add it

1
breadncheesetheking1OP•

Can't get the logic for start date = begining of last month, end date = end of last month, number of days = Len(last month)

1
mOnion•

What do you want your result to look like? What are you trying to do?

1
[deleted]•

[deleted]

1
Quiet___Lad•

https://github.com/camiolo/Power_Query/blob/main/Power%20Query%20Template.xltx

In my Excel file, I have a Function Month_Generator_Loop.

Here's a code of that function to generate Month's between two days.
It should also work if you Replace Text .AddMonths( with .AddDays(

let Input = (Start_Month as date, End_Month as date, Empty_List as list) => let Step_1 = List.Combine({Empty_List, {Start_Month}}), Step_2 = if Int64.From(Start_Month) < Int64.From(End_Month) then Month_Generator_Loop(Date.AddMonths(Start_Month,1), End_Month, Step_1) else Step_1 in Step_2 in Input

1
HughMunn•

This is my one-line Table Calendar:

​

= #table(type table[DateKey=date], List.Transform({Number.From(#date(2020,1,1))..Number.From(#date(2020,12,31))}, each {Date.From(_)}))
1
radioblaster•

M is a functional language and practicing with little things like this is how you get good at it!

let

Now = DateTime.LocalNow(),

PreviousMonth = Date.AddMonths(Now,-1),

StartOfPreviousMonth = Date.From(Date.StartOfMonth(PreviousMonth)),

DaysInPreviousMonth = Date.DaysInMonth(StartOfPreviousMonth)

in

List.Dates(StartOfPreviousMonth,DaysInPreviousMonth,#duration(1,0,0,0))

1
breadncheesetheking1OP•

This is exactly what I was looking for - many thanks for your help.

2