The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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! |
|
User | Count |
---|---|
15 | |
13 | |
9 | |
6 | |
6 |
User | Count |
---|---|
28 | |
18 | |
13 | |
9 | |
5 |