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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.