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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Julia2023
Helper I
Helper I

Count the number of weeks

Hi, can you help count the number of weeks in the selected month? Instead of using the hardcoded value '4', it should calculate the number of weeks in the selected month.

 

Measure:

Budget = 'Budget'[Budget $ SUM]/4

 

Thanks!

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@Julia2023<, First create a date table using below formula

Create a new table
DateTable =
ADDCOLUMNS (
CALENDAR (DATE(2020, 1, 1), DATE(2030, 12, 31)),
"Year", YEAR([Date]),
"Month", MONTH([Date]),
"MonthName", FORMAT([Date], "MMMM"),
"YearMonth", FORMAT([Date], "YYYYMM"),
"WeekOfYear", WEEKNUM([Date])
)

 

Then create a new measure in fact table to calculate number of weeks

dax
NumberOfWeeksInMonth =
VAR SelectedMonth = SELECTEDVALUE('DateTable'[Month])
VAR SelectedYear = SELECTEDVALUE('DateTable'[Year])
VAR FirstDayOfMonth = DATE(SelectedYear, SelectedMonth, 1)
VAR LastDayOfMonth = EOMONTH(FirstDayOfMonth, 0)
VAR FirstWeek = WEEKNUM(FirstDayOfMonth)
VAR LastWeek = WEEKNUM(LastDayOfMonth)
RETURN
LastWeek - FirstWeek + 1

 

Then update your measure

dax
Budget =
DIVIDE(
    SUM('Budget'[Budget $ SUM]),
    [NumberOfWeeksInMonth]
)



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

2 REPLIES 2
bhanu_gautam
Super User
Super User

@Julia2023<, First create a date table using below formula

Create a new table
DateTable =
ADDCOLUMNS (
CALENDAR (DATE(2020, 1, 1), DATE(2030, 12, 31)),
"Year", YEAR([Date]),
"Month", MONTH([Date]),
"MonthName", FORMAT([Date], "MMMM"),
"YearMonth", FORMAT([Date], "YYYYMM"),
"WeekOfYear", WEEKNUM([Date])
)

 

Then create a new measure in fact table to calculate number of weeks

dax
NumberOfWeeksInMonth =
VAR SelectedMonth = SELECTEDVALUE('DateTable'[Month])
VAR SelectedYear = SELECTEDVALUE('DateTable'[Year])
VAR FirstDayOfMonth = DATE(SelectedYear, SelectedMonth, 1)
VAR LastDayOfMonth = EOMONTH(FirstDayOfMonth, 0)
VAR FirstWeek = WEEKNUM(FirstDayOfMonth)
VAR LastWeek = WEEKNUM(LastDayOfMonth)
RETURN
LastWeek - FirstWeek + 1

 

Then update your measure

dax
Budget =
DIVIDE(
    SUM('Budget'[Budget $ SUM]),
    [NumberOfWeeksInMonth]
)



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam, thank you, this helped. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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