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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Selded
Helper III
Helper III

Custom week per month

I have a date table with week number based on the calender year. Each week starts from monday and ends on sunday. I want to create a custom week number based on months, each month will have week1, 2, 3,4,5.

 

Below is a sample of my date table. 

 

Selded_0-1597750109611.png

 

Thanks for the assistance.

3 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Selded , Try new columns like. You might have some the dependent colums with different name

 

Start Month = STARTOMONTH('Date'[Date])
WeekDay = WEEKDAY([Date],2) //monday
Start of Week = [Date] -[WeekDay]+1 //monday
Month Week = QUOTIENT(DATEDIFF(Minx(FILTER('Date',[Start Month]=EARLIER([Start Month])),'Date'[Start of Week]),[Date],DAY),7)+1

View solution in original post

vanessafvg
Super User
Super User

in power query under transform ribbon bar, select  date (has a calendar looking thing) drop down to  week from the menu and you should be able to choose week of month there, duplicate your date column before you do this.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




View solution in original post

@vanessafvg 

 

This worked , but unfortuantely my date table has week day starting on monday instead of Sunday. how do i edit the start day of my week to get this sorted correctly.

View solution in original post

7 REPLIES 7
vanessafvg
Super User
Super User

in power query under transform ribbon bar, select  date (has a calendar looking thing) drop down to  week from the menu and you should be able to choose week of month there, duplicate your date column before you do this.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg 

 

This worked , but unfortuantely my date table has week day starting on monday instead of Sunday. how do i edit the start day of my week to get this sorted correctly.

here is good article explaining how to adjust that There is a function called StartOfWeek that displays the start of the week in Power Query formula language.

Syntax: Date.StartOfWeek(<date>)

The week starts on Sunday and runs through to Saturday. To use Monday to Friday, you can add a day to it using the function Date.AddDays(<date>, 1).

https://carldesouza.com/power-query-language-m-start-week/

then you can write code in the custom column to adjust things the way you want to...




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg @amitchandak 

 

Thank you both, i got the week numbers correctly. 

 

please is there a way to for the column to read week 1 , week 2, instead of 1,2, 3.

 

Selded_0-1597755618211.png

 

Thank you 

just create a new column concatenating"week" + week no.




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




amitchandak
Super User
Super User

@Selded , Try new columns like. You might have some the dependent colums with different name

 

Start Month = STARTOMONTH('Date'[Date])
WeekDay = WEEKDAY([Date],2) //monday
Start of Week = [Date] -[WeekDay]+1 //monday
Month Week = QUOTIENT(DATEDIFF(Minx(FILTER('Date',[Start Month]=EARLIER([Start Month])),'Date'[Start of Week]),[Date],DAY),7)+1

@amitchandak 

 

Thanks, this fixes the issue.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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