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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Power Query How to Turn any day into a Monday

Hello,

 

I have a column with a list of dates, about 20k records.

 

What I need to do is convert every date into the first Monday of the week.

 

4/7/2020 > 4/6/2020

4/12/2020 > 4/6/2020

4/13/2020 > 4/13/2020

4/23/2020 > 4/20/2020

 

Is there anyway to do this without having a huge lookup table for everyday of the week?  In Excel I can use something like:

(A2+1)-WEEKDAY((A2+1)-2)

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I was actually looking for a solution in M for PowerQuery, but your formula got me thinking.  Here is what I ended up with:

 

Date.AddDays([Date],-Date.DayOfWeek([Date],Day.Monday))

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

This in DAX- This will week strat as Monday and Week-End as Sunday for all the dates between Monday and Sunday

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)

Anonymous
Not applicable

I was actually looking for a solution in M for PowerQuery, but your formula got me thinking.  Here is what I ended up with:

 

Date.AddDays([Date],-Date.DayOfWeek([Date],Day.Monday))

Anonymous
Not applicable

What I want to transform the dates column so if the date is Saturday, 07 Nov 2020 to become 09 Nov 2020, if the date is Sunday, 08 Nov 2020 to become 09 Nov 2020, else, to keep the date as it is? Any help please?

Hi,

This calculated column formula works

=Table1[Date]+SWITCH(WEEKDAY(Table1[Date],2),1,0,2,0,3,0,4,0,5,0,6,2,7,1)

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Excuse my ignorace, is this DAX or M? As I'm searching for a solution of M Power Query. My knowledge is really limited too, so, may I ask you please to provide the formula for these entries: Table. [Date], thank you.

Hi @Anonymous ,

Thanks for sharing your solution. It is working perfectly. Please accept the answer as a solution. Then more people who have the same requirement will benefit from the thread.

 

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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