Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi everyone,
I have a problem trying to get the correct week number of the month. In some months the firts day of month starts on Saturday or Sunday and the function WeekNumber recognize it as the fisrt week of month and the second week starts on Monday. I need the week starts on Monday.
For example:
Now I using this formula to get the week number of month:
Thanks for the help
DEFINE TABLE
Dates =
SELECTCOLUMNS(
CALENDAR(
date(2020, 6, 1),
date(2020, 8, 1) - 1
),
"@Date", [Date],
"@DayNumber",
// 2 => Monday is 1
WEEKDAY( [Date], 2 ),
"@DayName",
FORMAT( [Date], "ddd" )
)
EVALUATE
var DatesWithPartialSolution =
ADDCOLUMNS(
Dates,
"@MondaysBackCount",
var CurrentDate = [@Date]
var MonthStartDate =
EOMONTH( CurrentDate, -1 ) + 1
return
COUNTROWS(
FILTER(
Dates,
MonthStartDate <= [@Date]
&&
[@Date] <= CurrentDate
&&
[@DayNumber] = 1
)
)
)
return
ADDCOLUMNS(
DatesWithPartialSolution,
"@Final",
// find the latest number
// that's not blank
var CurrentDate = [@Date]
return
MAXX(
TOPN(1,
FILTER(
DatesWithPartialSolution,
[@Date] <= CurrentDate
&&
NOT( ISBLANK( [@MondaysBackCount] ) )
),
[@Date],
DESC
),
[@MondaysBackCount]
)
)
Run the above in DAX Studio or any Power BI client to see what it does. The @Final column stores the number of the week according to your requirement.
So you want the first week of every month to start on the first Monday of the month? But then this means that some days in other months will belong to weeks of the previous months. Do you realize this? From this stems the fact that weeks will not divide months evenly and they will cross months' boundaries.