Forum Discussion
First friday of every month - Power Query
- 4 years ago
mb0307 my bad, I didnt understand your question correctly! You can either add a custom column based on your Date column and fetch the first friday of each month for your calendar table:
Date.StartOfWeek(#date(Date.Year([Date_Key]),Date.Month([Date_Key]),7),Day.Friday)or, you can create a table with the last 12 months and add a custom column to fetch the correspondent first friday of the month:
let Dates = Table.FromList( List.Generate( ()=> [Month Start = Date.StartOfMonth(Date.AddMonths(DateTime.LocalNow(),-12)), idx = 11], each [idx] >= 0, each [Month Start = Date.StartOfMonth(Date.AddMonths(DateTime.LocalNow(),-[idx])), idx = [idx]-1], each [Month Start]), Splitter.SplitByNothing(),{"Month Start"}), dateType = Table.TransformColumnTypes(Dates,{"Month Start", Date.Type}), #"Added Custom" = Table.AddColumn(dateType, "First Friday", each Date.StartOfWeek(#date(Date.Year([Month Start]),Date.Month([Month Start]),7),Day.Friday)) in #"Added Custom"Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!
You can also check out my LinkedIn!
Best regards,
Gonçalo Geraldes - 4 years ago
mb0307 hey there! No problem at all! The code is pretty similar actually:
let Dates = Table.FromList( List.Generate( ()=> [Month End = Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow(),-12)), idx = 11], each [idx] >= 0, each [Month End = Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow(),-[idx])), idx = [idx]-1], each [Month End]), Splitter.SplitByNothing(),{"Month End"}), dateType = Table.TransformColumnTypes(Dates,{"Month End", Date.Type}), #"Added Custom" = Table.AddColumn(dateType, "Last Friday", each Date.AddDays([Month End], -Date.DayOfWeek([Month End],Day.Friday))) in #"Added Custom"For additional help, please @ me in your reply!
You can also check out my LinkedIn!
Best regards,
Gonçalo Geraldes
mb0307 hey there! No problem at all! The code is pretty similar actually:
let
Dates = Table.FromList(
List.Generate(
()=> [Month End = Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow(),-12)), idx = 11],
each [idx] >= 0,
each [Month End = Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow(),-[idx])), idx = [idx]-1],
each [Month End]),
Splitter.SplitByNothing(),{"Month End"}),
dateType = Table.TransformColumnTypes(Dates,{"Month End", Date.Type}),
#"Added Custom" = Table.AddColumn(dateType, "Last Friday", each Date.AddDays([Month End], -Date.DayOfWeek([Month End],Day.Friday)))
in
#"Added Custom"For additional help, please @ me in your reply!
You can also check out my LinkedIn!
Best regards,
Gonçalo Geraldes
goncalogeraldes superb! perfect result. THANKS A LOT 🙂