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, 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!
Solved! Go to Solution.
@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
Proud to be a 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
Proud to be a Super User! |
|