Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
joshua1990
Post Prodigy
Post Prodigy

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? 

2 ACCEPTED SOLUTIONS

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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

dax
Community Support
Community Support

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.

 

View solution in original post

6 REPLIES 6
mahoneypat
Microsoft Employee
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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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

dax
Community Support
Community Support

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.

 

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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Greg_Deckler
Community Champion
Community Champion

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

?


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.