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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
lawadaa
Helper I
Helper I

count number of days in a month week

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

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.

vtangjiemsft_0-1686535933858.png

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. 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

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.

vtangjiemsft_0-1686275901909.png

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

Anonymous
Not applicable

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.

vtangjiemsft_0-1686535933858.png

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. 

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.