[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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,200
Messages
6,123,601
Members
449,109
Latest member
Sebas8956

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