Forum Discussion
How can I get last Friday date based on Today in a Custom Column of Power Query please?
- 2 years ago
Hi Anonymous
CurrentDate = DateTime.Date( DateTime.LocalNow() ), LastFridayColumn = Table.AddColumn(LastStepName, "LastFriday", each if Date.DayOfWeek(CurrentDate) >= 5 then Date.AddDays(CurrentDate, -Date.DayOfWeek(CurrentDate) - 3 + 7) else Date.AddDays(CurrentDate, -Date.DayOfWeek(CurrentDate) - 3), type date)The default DayOfWeek is zero for Monday to 6 Sunday.
EDIT: today is Friday - this will choose the previous Friday, 29 March. You'll have to modify the formula slightly if you want today to return today.
- Anonymous2 years ago
Thank you belvoir99, it worked for me
= Table.AddColumn(#"Filtered Rows4", "LastFriday", each if Date.DayOfWeek(DateTime.Date( DateTime.LocalNow() )) >= 5 then Date.AddDays(DateTime.Date( DateTime.LocalNow() ), -Date.DayOfWeek(DateTime.Date( DateTime.LocalNow() )) - 3 + 7) else Date.AddDays(DateTime.Date( DateTime.LocalNow() ), -Date.DayOfWeek(DateTime.Date( DateTime.LocalNow() )) - 3), type date)
Hi Anonymous
Try to modify the formula to :
Date.AddDays(Date.From(DateTime.LocalNow()),-Date.DayOfWeek(Date.From(DateTime.LocalNow()),5)
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Ritaf1983 , still same