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.
I'm trying to create a column that calculates the number of days within a week in month. for example week1 of june has the following dates: 1-6-2023 till 3-6-2023 so number of days =3
w2 dates 4-6-2023 till 10-6-2023 so number of days =7
and so on for every week in the month
Solved! Go to Solution.
Hi @lawadaa ,
(1) We can create a calculated column.
WeekOfMonth =
VAR WeekStart = 0
VAR CurrentDate = 'DateTable'[Date]
VAR MonthStart = DATE(YEAR(CurrentDate), MONTH(CurrentDate), 1)
VAR MonthEnd = EOMONTH(CurrentDate, 0)
VAR WeekNumber = INT((CurrentDate - MonthStart + WEEKDAY(MonthStart - WeekStart) + 6) / 7)
RETURN WeekNumber
(2) We can create a measure.
DaysInWeekOfMonth =
VAR SelectedWeek = SELECTEDVALUE('DateTable'[WeekOfMonth])
VAR MinDate = CALCULATE(MIN('DateTable'[Date]), 'DateTable'[WeekOfMonth] = SelectedWeek)
VAR MaxDate = CALCULATE(MAX('DateTable'[Date]), 'DateTable'[WeekOfMonth] = SelectedWeek)
RETURN IF(ISBLANK(SelectedWeek), BLANK(), DATEDIFF(MinDate, MaxDate, DAY) + 1)
(3)Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @lawadaa ,
According to your description, here are my steps you can follow as a solution.
(1) We can create a date table.
DateTable = CALENDAR(DATE(2023,1,1),DATE(2023,12,31))
(2) We can create two calculated columns.
WeekNumber = WEEKNUM([Date], 2)
MonthNumber = MONTH('DateTable'[Date])
(3) We can create a measure.
DaysInWeekInMonth =
VAR SelectedMonth = SELECTEDVALUE('DateTable'[MonthNumber])
VAR SelectedWeek = SELECTEDVALUE('DateTable'[WeekNumber])
RETURN
CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
'DateTable'[MonthNumber] = SelectedMonth &&
'DateTable'[WeekNumber] = SelectedWeek
)
)
(4)Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
this measure calculates the number of days in yearly week not in a monthly week. and i need the week to start from sunday to saturday not monday to sunday
Hi @lawadaa ,
(1) We can create a calculated column.
WeekOfMonth =
VAR WeekStart = 0
VAR CurrentDate = 'DateTable'[Date]
VAR MonthStart = DATE(YEAR(CurrentDate), MONTH(CurrentDate), 1)
VAR MonthEnd = EOMONTH(CurrentDate, 0)
VAR WeekNumber = INT((CurrentDate - MonthStart + WEEKDAY(MonthStart - WeekStart) + 6) / 7)
RETURN WeekNumber
(2) We can create a measure.
DaysInWeekOfMonth =
VAR SelectedWeek = SELECTEDVALUE('DateTable'[WeekOfMonth])
VAR MinDate = CALCULATE(MIN('DateTable'[Date]), 'DateTable'[WeekOfMonth] = SelectedWeek)
VAR MaxDate = CALCULATE(MAX('DateTable'[Date]), 'DateTable'[WeekOfMonth] = SelectedWeek)
RETURN IF(ISBLANK(SelectedWeek), BLANK(), DATEDIFF(MinDate, MaxDate, DAY) + 1)
(3)Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
41 | |
21 | |
21 | |
14 | |
13 |
User | Count |
---|---|
43 | |
36 | |
33 | |
18 | |
18 |