[Power Query] - M Language

jajatidev

Board Regular
Joined
Jul 29, 2016
Messages
69
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have used the following function to populate the week column. However, now I need to offset the week date by bringing it forward by 2 weeks while adhering to the following logic;

1. if the offset week based on CRD is before the current week then it will be the current week
2. if the CRD field is blank then the week filed will always be the current week

Power Query:
if [CRD] is null then Date.StartOfWeek(DateTime.Date(DateTime.LocalNow()),1) else Date.StartOfWeek([CRD],1)


MaterialQtyCRDWeek
A1A30A-KGJ20004/26/202404/22/2024
1NR73A-K1H29004/01/2024
A1A30A-KGJ25004/01/2024
5RA32F-KGJ32507/26/202407/22/2024
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
was able to work the function.

Power Query:
if [CRD] is null or Date.AddWeeks(Date.StartOfWeek([CRD],1),-2) < Date.StartOfWeek(DateTime.Date(DateTime.LocalNow()),1) then Date.StartOfWeek(DateTime.Date(DateTime.LocalNow()),1) else Date.AddWeeks(Date.StartOfWeek([CRD],1),-2)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,195
Messages
6,123,572
Members
449,108
Latest member
rache47

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top