Forum Discussion

joshua1990's avatar
joshua1990
Post Prodigy
6 years ago
Solved

Column with Date.EndOfWeek for last week

Hello everybody!

I need to add a column with the end date for the last week.

The following M-Code formats the end of week based on a date:

Date.EndOfWeek(#date(2011, 5, 14))

How can be this transferred for the last week? 

  • mahoneypat's avatar
    mahoneypat
    6 years ago

    You can use Date.StartOfWeek, or subtract the desired number of days from that expression (e.g., -7).

     

    If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

  • dax's avatar
    dax
    6 years ago

    Hi joshua1990 , 

    You could refer to mahoneypat ' suggestion , use Date.StartOfWeek(Date.From(DateTime.LocalNow())) to get start day of current week, then you could -1 to get the end day of last week by below code

    = Date.AddDays(Date.StartOfWeek(Date.From(DateTime.LocalNow())),-1)

     

    Best Regards,
    Zoe Zhi

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

6 Replies

    • joshua1990's avatar
      joshua1990
      Post Prodigy

      Thanks!

      But I need a dynamic function for the last week.

      It should be not fixed for just one week.

      I need after every refresh (once a week) the end for the corresponding week.

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    To do it in query, use    Date.EndOfWeek(Date.From(DateTime.LocalNow()))

     

    If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

    • joshua1990's avatar
      joshua1990
      Post Prodigy

      Thanks! And how can I reference to last week? This will me show the current week.

      • mahoneypat's avatar
        mahoneypat
        Microsoft Employee

        You can use Date.StartOfWeek, or subtract the desired number of days from that expression (e.g., -7).

         

        If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

        Regards,

        Pat