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
Jose_Freire
New Member

Need help to create week number

Hi, 

 

I´m creating a new Dashboard and I need a week number to represent in a bar graphic. Similar to this:

Captura.PNG

How can I create a WeekNum column?

https://drive.google.com/file/d/1o4QRpKhBBjzIdlIdfG_of583fCPVeYCs/view?usp=sharing https://drive.google.com/file/d/1o4QRpKhBBjzIdlIdfG_of583fCPVeYCs/view?usp=sharing 

 

Thaanks a lot!

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Jose_Freire ,

According to my understand, you want to calculate the Week Number of each month , then use Month as the parent X-axis and Week Number as  sub X-axis, right?

You could add a Date column based on Month, MonthID and Day columns like this:

Date =
DATE ( LEFT ( [MontID], 4 ), RIGHT ( [MontID], 2 ), [Day] )

Then use the following formula to create the Week Number column:

WeekNumber =
1 + WEEKNUM ( [Date] )
    - WEEKNUM ( STARTOFMONTH ( 'Tabla1'[Date] ) )

Please follow the steps shown in the below gif:

10.26.6.1.gif

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

View solution in original post

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hi @Jose_Freire ,

According to my understand, you want to calculate the Week Number of each month , then use Month as the parent X-axis and Week Number as  sub X-axis, right?

You could add a Date column based on Month, MonthID and Day columns like this:

Date =
DATE ( LEFT ( [MontID], 4 ), RIGHT ( [MontID], 2 ), [Day] )

Then use the following formula to create the Week Number column:

WeekNumber =
1 + WEEKNUM ( [Date] )
    - WEEKNUM ( STARTOFMONTH ( 'Tabla1'[Date] ) )

Please follow the steps shown in the below gif:

10.26.6.1.gif

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

FrankAT
Community Champion
Community Champion

Hi @Jose_Freire 

what is your definition of a weeknumber of the month? When starts the first week oh month?

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

amitchandak
Super User
Super User

@Jose_Freire , Week of month you can refer

 

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

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

rogletree
Helper III
Helper III

Hey, there's a power query function called WeekOfMonth() that should be able to do what you want.

https://docs.microsoft.com/en-us/powerquery-m/date-weekofmonth

In order to get your x-axis similar to your picture, you could create a new custom column and do something like:

Custom

= Date.Month([*yourDateField*]) + Date.WeekOfMonth([*yourDateField*])

If that doesn't quite work try using Text.From() and putting the above formula inside the parenthesis. It will make the column as text data type.

There may be a better way to do it but that's just what I thought of off the top of my head.

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.

Top Solution Authors