Cheat Sheet — Any Weekday’s Week Start Date— Just one variable apart

Amit Chandak
ChandakAmit
Published in
2 min readMay 30, 2022

--

Objective — To have a calendar that has a week start date that can start on any weekday

Solution: The solution should use a weekday as a variable and should create a calendar that can have a start date on a given weekday.

I have previously given a solution — here. Now I came up with a new code using just one variable. Check week start date and weekend date.

_weekday is variable, where one needs to provide values from 1 to 7

Code

Date = 
var _weekday =7 //Sunday- 1, Monday -2 , Tuesday -3, Wednesday -4, Thursday -5, Friday -6, Saturday -7
var _left = 7-_weekday
var _tab = ADDCOLUMNS(CALENDAR(date(2018,1,1),Date(2022,12,31)),”Month Year”,format([Date],”MMM-YYYY”),
“Weekday” , WEEKDAY([date]),
“Week Start Date Sunday” , [Date] + -1*WEEKDAY([Date])+1,
“Week End Date Sunday” , [Date] + -1*WEEKDAY([Date])+7,
“Week Start Date” , [Date] + -1*if(WEEKDAY([Date])<_weekday,WEEKDAY([Date],1)+ _left,WEEKDAY([Date],1)-1* _weekday),
“Week End Date” , ([Date] + -1*if(WEEKDAY([Date])<_weekday,WEEKDAY([Date],1)+ _left,WEEKDAY([Date],1)-1* _weekday))+6
)
return _tab

Download the file from — here

Click Here to access all my blogs and videos in a jiffy via an exclusive visual glossary using Power BI.
Please like, share, and comment on these. Your suggestions on improvement, challenges, and new topics will help me explore more.

You Can watch my Power BI Tutorial Series on My Channel, Subscribe, Like, and share

--

--

Amit Chandak
ChandakAmit

Amit has 20+ years of experience in Business Intelligence, Analytics, Data Science. He is Chief Analytics Officer at Kanerika & Power BI community Super User