Weekdays and Day off - date Table M Code

Hi,

Attached a part of the Date M Code , Concerning the working days and days off

My week starts on Saturday and ending on Friday , and i already chose 1-7 , for that

in the column of “is working day” i found that “Saturday and Sunday” are considered Days off.

What i need is changing the M Code in attached screenshot to be Friday is only “not working day”
Thanks,
Abeer

1 Like

Hi @Abeer ,

I am attaching sample file for your reference. Please try to use that logic.
In case not able to apply same logic than please share the sample file.
Day Name.xlsx (25.2 KB)

Regards,
Rajender

1 Like

Hi @Abeer,
To set Friday as the only non-working day of the week you can modify the following line of code:

InsertIsWorkingDay = Table.AddColumn(InsertIsAfterToday, “IsWorkingDay”, each if Date.DayOfWeek([Date], Day.Saturday) = 6 then false else true, type logical),

Saturday: 0
Sunday: 1
Monday: 2
Tuesday: 3
Wednesday: 4
Thursday: 5
Friday: 6

In this other way, we would also obtain the same result:
InsertIsWorkingDay = Table.AddColumn(InsertIsAfterToday, “IsWorkingDay”, each if Date.DayOfWeek([Date], Day.Monday) = 4 then false else true, type logical),

Monday: 0
Tuesday: 1
Wednesday: 2
Thursday: 3
Friday: 4
Saturday: 5
Sunday: 6

Regards,

1 Like

Hi @jafernandezpuga ,

I did as you explained and worked .

can you Pls advise if i want “Friday and Saturday” to be “Not Working Day”

how it should be and if you can explain the this logic.
thanks,
Abeer

Hi @Abeer,
The Date.DayOfWeek([Date], Day.Monday) function returns a value from 0 to 6 starting in this case with Monday, since we passed Day.Monday as the second parameter

Monday: 0
Tuesday 1
Wednesday: 2
Thursday: 3
Friday: 4
Saturday: 5
Sunday: 6

To set Friday and Saturday the return value has to be 4 or 5.

InsertIsWorkingDay = Table.AddColumn(InsertIsAfterToday, “IsWorkingDay”, each if Date.DayOfWeek([Date], Day.Monday) = 4 or Date.DayOfWeek([Date], Day.Monday) = 5 then false else true,

Regards,

1 Like

Hi @jafernandezpuga ,
Thank you it worked.
Abeer

1 Like