cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vacacelaivan Frequent Visitor
Frequent Visitor

Need Help with Custom Week of month number

Hi all, I've been trying to get around this problem with no luck.

 

Trying to create a column for the week number of the month, with the week always starting on Monday and ending on a Sunday. 

Months will have 4 or 5 weeks

 

The below DAX almost works: 

 

weekinmonth = 1 + WEEKNUM ( Dates[Date],21)-WEEKNUM( STARTOFMONTH (Dates[Date]),21)

 

 

However, if the month does not end on a Sunday, the week number changes back to 1 in the middle of the week which is incorrect.

I was unable to upload a screenshot at work, but in the example below Feb 01 - 04 (in red) should be in Week 5, while Monday Feb 05 should be week 1 (in blue).

 

DateWeek of Month
Monday, Jan 22, 20184
Tuesday, Jan 23, 20184
Wednesday, Jan 24, 20184
Thursday, Jan 25, 20184
Friday, Jan 26, 20184
Saturday, Jan 27, 20184
Sunday, Jan 28, 20184
Monday, Jan 29, 20185
Tuesday, Jan 30, 20185
Wednesday, Jan 31, 20185
Thursday, Feb 01, 20181
Friday, Feb 02, 20181
Saturday, Feb 03, 20181
Sunday, Feb 04, 20181
Monday, Feb 05, 20182

 

Any help on this is extremely appreciated.

Ivan

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Need Help with Custom Week of month number

Hi @vacacelaivan,

 

Based on my test, it is not possible to meet your requirement currently. You can come up a new idea about that and add your comments there to improve Power BI and make this feature coming sooner.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
abbasabdulla Frequent Visitor
Frequent Visitor

Re: Need Help with Custom Week of month number

Hi,

Does changing 21 to 2 in your function solve this? Why you put the 21?

 

weekinmonth = 1 + WEEKNUM ( Dates[Date],2)-WEEKNUM( STARTOFMONTH (Dates[Date]),2)

vacacelaivan Frequent Visitor
Frequent Visitor

Re: Need Help with Custom Week of month number

I tried both methods WEEKNUM (Date, 2) and WEEKNUM (DATE, 21), but both don't work in this case.

The parameter 21 is to return weeknumbers according to ISO 8601.http://blog.gbrueckl.at/2012/04/iso-8601-week-in-dax/ and a number of other articles in this forum.

 

Bump?!?

abbasabdulla Frequent Visitor
Frequent Visitor

Re: Need Help with Custom Week of month number

Try using this function

= 1 + WEEKNUM ( Dates[Date],2)-WEEKNUM( DATE(YEAR(Dates[Date]),MONTH(Dates[Date]),1),2)
Community Support Team
Community Support Team

Re: Need Help with Custom Week of month number

Hi @vacacelaivan,

 

Based on my test, it is not possible to meet your requirement currently. You can come up a new idea about that and add your comments there to improve Power BI and make this feature coming sooner.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.