Forum Discussion
Week Start calculation
- 8 years ago
Ok...so this appears to work and do what I need:
WeekStart
= Table.AddColumn(#"WeekStart", each Date.ToText(Date.StartOfWeek([Date], Day.Sunday),"MM/dd/yyyy"))
WeekStart_WeekEnd
= Table.AddColumn(#"WeekStart_WeekEnd", each Date.ToText(Date.StartOfWeek([Date], Day.Sunday),"MM/dd/yyyy") & "-" & Date.ToText(Date.EndOfWeek([Date], Day.Sunday),"MM/dd/yyyy"))
I'll leave this here so the next person trying this can hopefully find it and not bang their head for a full day.
I appreciate all the help.
Hi
The below Dax will help to get the week start date. I am assuming that Sunday is your week start date.
WeekStartDate = Sheet2[Date]- WEEKDAY(Sheet2[Date],1)+1 // Sunday as Week start date
WeekStartDate = Sheet2[Date]- WEEKDAY(Sheet2[Date],2)+1 // Monday as Week start date
Hope this is what you are looking for.
Thansk
Raj
- Nonsensely7 years agoAdvocate I
Thank you, Raj. This is the quickest and easiest solution I've found.
- Anonymous7 years agoNot applicable
Cool Nonsensely.
- mcnater8 years agoAdvocate I
Is there a way to do it in the Query Editor? I'm using the "Ultimate Calendar" query load and am wondering if can just be added there instead of DAX so all the Date Logic is on the calendar. We are just looking for a Sunday start yes. Is that possible do you know?
- Greg_Deckler8 years agoCommunity Champion
I have personally found that instead of dealing with dates in the Query Editor that it is instead preferrable to bash my head repeatedly into a brick wall until I pass out from blood loss and forget that I was trying to attempt something so foolish. But ImkeF might be able to assist.
- mcnater8 years agoAdvocate I
Haha...but if I have a nice Calendar query, I can simply copy it from one report to the next when I create them. Adding in a DAX measure would add 1 more step would it not? Not the end of the world but I'm trying to keep things simple and tidy. Maybe I'm just missing something but that's the goal anyway.
- Anonymous7 years agoNot applicable
Can you please help me understand how to use your DAX example? Is it for a column or Table or Measure? Is Sheet2 the name of the table? and [Date] the name of the Date field in the Table? I am unable to figure out how to get it to work.
- elojero6 years agoRegular Visitor
Elegant!!
- Awambugu206 years agoRegular Visitor
Thanking you kindly 🙂