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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Chippy
Frequent Visitor

Number of days in Month from a date range

I am looking for a way to report in PowerBI leave/absences from work by employee and department by month, however I don't have daily breakdown but date range only, as per example, where for employee 1000675 (2nd row) has taken 16 days over two months. How can I work out how many working days (Mon to Fri) were taken for each of Dec and Jan?

 

EmployeeDepartmentLeave TypeStart DateEnd DateDays Taken
1000706Regional SalesMaternity Leave Unpaid18/03/2424/01/25            218.00
1000675Finance LeadershipAnnual Leave27/12/2417/01/25               16.00
2302135Regional SalesAnnual Leave23/12/2410/01/25               13.00
2303149Regional SalesAnnual Leave27/12/248/01/25                  9.00
1000812Convenience & SpecialtyAnnual Leave20/12/247/01/25               11.00
1000275P&P LeadershipAnnual Leave24/12/246/01/25                  6.00
1000769Operations LeadershipAnnual Leave23/12/243/01/25                  8.00
2304494Marketing ManagementAnnual Leave23/12/243/01/25                  8.00
1176278Finance LeadershipAnnual Leave16/12/243/01/25               13.00
1000379RetailAnnual Leave24/12/241/01/25                  5.00
1405149Operations LeadershipAnnual Leave23/12/241/01/25                  6.00
1000477Regional SalesAnnual Leave9/12/241/01/25               15.00
1000081Finance LeadershipAnnual Leave31/12/2431/12/24                  0.45
2 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @Chippy - Hope in your data model Calendar Table that includes every date in your data range.

add a new column as like below:

IsWorkingDay = IF(WEEKDAY('Calendar'[Date],2) <= 5, 1, 0)

 

start creating a  measure to count the total working days for a leave period

TotalWorkingDays =
CALCULATE(
COUNTROWS('Calendar'),
'Calendar'[Date] >= MIN('LeaveData'[Start Date]) &&
'Calendar'[Date] <= MAX('LeaveData'[End Date]),
'Calendar'[IsWorkingDay] = 1
)

 

Next measure to split the working days by month

WorkingDaysInMonth =
CALCULATE(
COUNTROWS('Calendar'),
'Calendar'[Date] >= MAX(DATE(YEAR('Calendar'[Date]), MONTH('Calendar'[Date]), 1)) &&
'Calendar'[Date] <= MAX('LeaveData'[End Date]),
'Calendar'[IsWorkingDay] = 1
)

 

Using a visual or filter in Power BI, you can now filter the leave records by month and calculate how many working days were taken in each of those months.

 

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

dk_dk
Super User
Super User

Hi @Chippy 

 

Based on this blog post from @amitchandak :

 

In Power Query, you add a custom column as per the blog post and expand to new rows.

You can add another custom column to get the day of the week using Date.DayOfWeekName().

 

Here is the whole M query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZLRTsIwFIZfZdk1Yee0XbtdGhOvJBKJV8hFAyfYOMsyCglvb8ciqzrKjL1quub7T7/9y2WKAKBAppP0mbZmZ3WVLHRFe38w044aa9wpeSR9pOTF1tps/AcsMuAZE37LRAaYsdxvk2AxLKYA6WrSBUjVXngwVts1tbQNNfs3U/vDO2sPPvOc0PJUhqxDoxpE+4XyC844MOT50PQ/wbwHw1UwD8AcRTkG3E9cXOP6VYY+CmT+0v3OHskaap28HgCYTBY1rY2u3GkgBy4518VgmMLO1ucdeh7XLi5wGXmEDPFKtnqeamq084b28YBeP48EFIF/IUpxbmHzTs7YbTLTVm/pg6z7Px9RSaaKka1EeZved6eVw1XXHadNFdWNkWnzC1FA3rXx77pjAd/+p1BqRN3L22DMQ6wv+0jLHHvL/fb31DAVebpafQI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, Department = _t, #"Leave Type" = _t, #"Start Date" = _t, #"End Date" = _t, #"Days Taken" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", Int64.Type}, {"Department", type text}, {"Leave Type", type text}, {"Start Date", type date}, {"End Date", type date}, {"Days Taken", Int64.Type}}),
    #"Divided Column" = Table.TransformColumns(#"Changed Type", {{"Days Taken", each _ / 100, type number}}),
    #"Added Custom" = Table.AddColumn(#"Divided Column", "Custom", each List.Dates([Start Date], Duration.Days([End Date] -[Start Date]) +1 ,#duration(1,0,0,0) )),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom", "Days"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Days", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Day Name", each Date.DayOfWeekName([Days]))
in
    #"Added Custom1"

 

You will need to add some additional data about which days are red days / holidays. I noted that your Days Taken column excludes these from the total, even if they are on a weekday. Depending on the country, the red days are different so I did not include a step for this.

 

You can close and load.

 

Create a new measure:

 

Number of Weekdays = CALCULATE(COUNTROWS(LeaveData),LeaveData[Day Name] IN {"Monday","Tuesday","Wednesday","Thursday","Friday"})

You need to modify this measure so it filters out the red days/holidays as well.

 

 

And the result:

dk_dk_0-1729244134369.png

 

 

 

I hope this helps! Let me know if you have any questions.

 

 

 

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
dk_dk
Super User
Super User

Hi @Chippy 

 

Based on this blog post from @amitchandak :

 

In Power Query, you add a custom column as per the blog post and expand to new rows.

You can add another custom column to get the day of the week using Date.DayOfWeekName().

 

Here is the whole M query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZLRTsIwFIZfZdk1Yee0XbtdGhOvJBKJV8hFAyfYOMsyCglvb8ciqzrKjL1quub7T7/9y2WKAKBAppP0mbZmZ3WVLHRFe38w044aa9wpeSR9pOTF1tps/AcsMuAZE37LRAaYsdxvk2AxLKYA6WrSBUjVXngwVts1tbQNNfs3U/vDO2sPPvOc0PJUhqxDoxpE+4XyC844MOT50PQ/wbwHw1UwD8AcRTkG3E9cXOP6VYY+CmT+0v3OHskaap28HgCYTBY1rY2u3GkgBy4518VgmMLO1ucdeh7XLi5wGXmEDPFKtnqeamq084b28YBeP48EFIF/IUpxbmHzTs7YbTLTVm/pg6z7Px9RSaaKka1EeZved6eVw1XXHadNFdWNkWnzC1FA3rXx77pjAd/+p1BqRN3L22DMQ6wv+0jLHHvL/fb31DAVebpafQI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, Department = _t, #"Leave Type" = _t, #"Start Date" = _t, #"End Date" = _t, #"Days Taken" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", Int64.Type}, {"Department", type text}, {"Leave Type", type text}, {"Start Date", type date}, {"End Date", type date}, {"Days Taken", Int64.Type}}),
    #"Divided Column" = Table.TransformColumns(#"Changed Type", {{"Days Taken", each _ / 100, type number}}),
    #"Added Custom" = Table.AddColumn(#"Divided Column", "Custom", each List.Dates([Start Date], Duration.Days([End Date] -[Start Date]) +1 ,#duration(1,0,0,0) )),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom", "Days"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Days", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Day Name", each Date.DayOfWeekName([Days]))
in
    #"Added Custom1"

 

You will need to add some additional data about which days are red days / holidays. I noted that your Days Taken column excludes these from the total, even if they are on a weekday. Depending on the country, the red days are different so I did not include a step for this.

 

You can close and load.

 

Create a new measure:

 

Number of Weekdays = CALCULATE(COUNTROWS(LeaveData),LeaveData[Day Name] IN {"Monday","Tuesday","Wednesday","Thursday","Friday"})

You need to modify this measure so it filters out the red days/holidays as well.

 

 

And the result:

dk_dk_0-1729244134369.png

 

 

 

I hope this helps! Let me know if you have any questions.

 

 

 

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





rajendraongole1
Super User
Super User

Hi @Chippy - Hope in your data model Calendar Table that includes every date in your data range.

add a new column as like below:

IsWorkingDay = IF(WEEKDAY('Calendar'[Date],2) <= 5, 1, 0)

 

start creating a  measure to count the total working days for a leave period

TotalWorkingDays =
CALCULATE(
COUNTROWS('Calendar'),
'Calendar'[Date] >= MIN('LeaveData'[Start Date]) &&
'Calendar'[Date] <= MAX('LeaveData'[End Date]),
'Calendar'[IsWorkingDay] = 1
)

 

Next measure to split the working days by month

WorkingDaysInMonth =
CALCULATE(
COUNTROWS('Calendar'),
'Calendar'[Date] >= MAX(DATE(YEAR('Calendar'[Date]), MONTH('Calendar'[Date]), 1)) &&
'Calendar'[Date] <= MAX('LeaveData'[End Date]),
'Calendar'[IsWorkingDay] = 1
)

 

Using a visual or filter in Power BI, you can now filter the leave records by month and calculate how many working days were taken in each of those months.

 

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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.

Top Solution Authors