Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

How can I get last Friday date based on Today in a Custom Column of Power Query please?

Hi, How can I get last Friday date based on Today in a Custom Column of Power Query please? I tried the below solution, but if today is Friday, then the formula is giving today's date instead of la...
  • belvoir99's avatar
    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.

  • Anonymous's avatar
    Anonymous
    2 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)