Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
sabeensp
Helper IV
Helper IV

Week of the Month (Calculated Column)

Hello,

 

I have a Date Dimention table, in which I need to add calculated column (Week_Of) shown below in the image. I tried several IF Then else, but not beign able to do it so far. Can you please help?

2019-07-17_8-43-45.jpg

2 ACCEPTED SOLUTIONS

Oops my mistake, I misread.

 

WeekStarting = DimDate[Date] - WEEKDAY(DimDate[Date]) + 1




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

That's an easy enough change. WEEKDAY starts on Sunday by default, but you can change it to start on either Saturday or Monday by changing the second argument.

 

WeekStarting = DimDate[Date] - WEEKDAY(DimDate[Date], 2) + 1

Check out the documentation of WEEKDAY here.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

7 REPLIES 7
theov
Advocate II
Advocate II

Hi, You can use combination of WEEKNUM and STARTOFMONTH to get the week number in month or (month week name.)

 

Here is a good video explaining that also:

 

https://www.youtube.com/watch?v=Oq5WOmo94_Q

KHorseman
Community Champion
Community Champion

If you were creating this in the query editor it would be easy. There is a Date.WeekofMonth formula. So I'm going to assume you're writing this in DAX. The easiest way I can think of is to use the WEEKNUM formula, which returns the week number in the year. Subtract the WEEKNUM of the first week of the month from the weeknum of the week you're on, and that gives you the week of the month. Don't use the date of the first of the month though, because you'll mess up on weeks that start at the end of the previous month. Use the date of the last day of the week to find the first weeknum of the month.

 

WeekOfMonth = VAR weekending = DimDate[Date] - WEEKDAY(DimDate[Date]) + 7
RETURN WEEKNUM(weekending) - WEEKNUM(DATE(YEAR(weekending), MONTH(weekending), 1)) + 1




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@KHorsemanThanks, Yes, I'm doing that in DAX.

 

Your solution gives me the number of week, which I already have in column Day_Wk_Num.
What I'm looking for is what I have in column "Week_Of", which is basically the date of each week begining date, repeating for each day of that week.

 

2019-07-17_8-43-45.jpg

Oops my mistake, I misread.

 

WeekStarting = DimDate[Date] - WEEKDAY(DimDate[Date]) + 1




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks, apprecite your help.

@KHorsemanso, it is sort of working, but it is starting from Sunday, our work week starts from Monday through Sunday. I have a week day column 1 through 7 in there.

 

Sorry, I'm new to DAX. I do appreciat eyour help.

That's an easy enough change. WEEKDAY starts on Sunday by default, but you can change it to start on either Saturday or Monday by changing the second argument.

 

WeekStarting = DimDate[Date] - WEEKDAY(DimDate[Date], 2) + 1

Check out the documentation of WEEKDAY here.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.