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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
collinq
Super User
Super User

Total Working Days in a month based on slicer selection

Hi all,

 

I have attached a link to my pbix sample file (here - https://tinyurl.com/y522q5l7 )

I want to select a date range and retrieve the number of working days in each of those represented months.  So, if the date slicer were 8/1/20-8/15/20 that is the month of August.  The month of August has 21 working days in it (for my specific calendar anyway).   Therefore, I need the result of "21".

 

If the date slicer is 8/1/20-9/15/20 that is August and September.  August has 21 working days and September has 21 working days in my calendar file so I need to have a result of "42".

 

In my DateDim I have whether or not the date is a working day.  

 

I am having trouble getting the DAX right to give me that total working number of all the months and would be most appreciative if somebody could help me out.

 

Thanks!




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

Proud to be a Datanaut!
Private message me for consulting or training needs.




1 ACCEPTED SOLUTION
dedelman_clng
Community Champion
Community Champion

Hi @collinq -

 

This might not be that elegant, but give it a try:

 

NumWorkDays =
VAR __MinDt =
    CALCULATE ( MIN ( DateTab[Date] ), ALLSELECTED ( DateTab[Date] ) )
VAR __MaxDt =
    CALCULATE ( MAX ( DateTab[Date] ), ALLSELECTED ( DateTab[Date] ) )
VAR __MinMth =
    MONTH ( __MinDt )
VAR __MinYr =
    YEAR ( __MinDt )
VAR __MaxMth =
    MONTH ( __MaxDt )
VAR __MaxYr =
    YEAR ( __MaxDt )
VAR __MinDate =
    DATE ( __MinYr, __MinMth, 1 )
VAR __MaxDate =
    EOMONTH ( DATE ( __MaxYr, __MaxMth, 1 ), 0 )
RETURN
    CALCULATE (
        COUNTROWS (
            FILTER (
                ALL ( DateTab ),
                DateTab[Date] >= __MinDate
                    && DateTab[Date] <= __MaxDate
                    && DateTab[IsWorkDay]
            )
        )
    )

 

(IsWorkDay is a Boolean on the Date table marking Sat-Sun as false, so ignoring holidays)

 

2021-01-18 14_29_56-scratch4 - Power BI Desktop.png2021-01-18 14_29_39-scratch4 - Power BI Desktop.png

 

Should be able to span years, not just months.

 

Hope this helps

David

View solution in original post

2 REPLIES 2
dedelman_clng
Community Champion
Community Champion

Hi @collinq -

 

This might not be that elegant, but give it a try:

 

NumWorkDays =
VAR __MinDt =
    CALCULATE ( MIN ( DateTab[Date] ), ALLSELECTED ( DateTab[Date] ) )
VAR __MaxDt =
    CALCULATE ( MAX ( DateTab[Date] ), ALLSELECTED ( DateTab[Date] ) )
VAR __MinMth =
    MONTH ( __MinDt )
VAR __MinYr =
    YEAR ( __MinDt )
VAR __MaxMth =
    MONTH ( __MaxDt )
VAR __MaxYr =
    YEAR ( __MaxDt )
VAR __MinDate =
    DATE ( __MinYr, __MinMth, 1 )
VAR __MaxDate =
    EOMONTH ( DATE ( __MaxYr, __MaxMth, 1 ), 0 )
RETURN
    CALCULATE (
        COUNTROWS (
            FILTER (
                ALL ( DateTab ),
                DateTab[Date] >= __MinDate
                    && DateTab[Date] <= __MaxDate
                    && DateTab[IsWorkDay]
            )
        )
    )

 

(IsWorkDay is a Boolean on the Date table marking Sat-Sun as false, so ignoring holidays)

 

2021-01-18 14_29_56-scratch4 - Power BI Desktop.png2021-01-18 14_29_39-scratch4 - Power BI Desktop.png

 

Should be able to span years, not just months.

 

Hope this helps

David

Hi @dedelman_clng ,

 

Elegant or not, that is beautiful to me!  Thanks so much!!!  I was definitely going down a much different and eventually ineffective solution.  Thanks for your time and thanks for your effort!




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

Proud to be a Datanaut!
Private message me for consulting or training needs.




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.