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
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
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
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(_)}))
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))
This is exactly what I was looking for - many thanks for your help.
Just Google a calendar table and add it
Can't get the logic for start date = begining of last month, end date = end of last month, number of days = Len(last month)
What do you want your result to look like? What are you trying to do?
[deleted]