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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
PMnooBI
Frequent Visitor

How to filter work days of task based on date slicer

pbicom.PNG

 

As you can see I have a table visual with workdays of tasks. I would like to have another column that displays the work days within the date range set in the slicer. For example, the task on third row has 5 days worth of work since it starts on 29th and ends on 4th but the slicer is between 27th and 1st. Hence, I want another column displaying just 3 work days for that task as the work is being done on 29th 30th and 31st only. Please let me know how I can implement this even if a task ends or starts in between a set date range.

Thanks

 

The workday column is calculated as the difference between the start and end dates excluding the weekends

The date slicer has the calendar table date column added to it. The table visual displays the values from another data table called Assignments.

 

@Greg_Deckler @MFelix @amitchandak @Arul @Ahmedx 

1 ACCEPTED SOLUTION

Hi @PMnooBI ,

 

Try the following code:

days_ =
VAR maxselecteddate =
    MAX ( Calendar[Date] )
VAR minselecteddate =
    MIN ( Calendar[Date] )
VAR startdatevalue =
    MAX ( minselecteddate, MIN ( 'Table (2)'[AssignementStartDate] ) )
VAR enddatevalue =
    MIN ( mAXselecteddate, MIN ( 'Table (2)'[AssignementFinishDate] ) )
VAR days_total =
    NETWORKDAYS ( startdatevalue, enddatevalue )
VAR TableValues =
    ADDCOLUMNS (
        'Table (2)',
        "DaysTotal",
            VAR net_days =
                NETWORKDAYS (
                    MAX ( minselecteddate, 'Table (2)'[AssignementStartDate] ),
                    MIN ( mAXselecteddate, 'Table (2)'[AssignementFinishDate] )
                )
            RETURN
                IF ( net_days > 0, net_days )
    )
RETURN
    SUMX ( TableValues, [DaysTotal] )

MFelix_0-1680165096579.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

11 REPLIES 11
MFelix
Super User
Super User

Hi @PMnooBI ,

 

Try the following code:

days_ = 
var maxselecteddate = MAX(Calendar[Date])
var minselecteddate = MIN(Calendar[Date])
var startdatevalue = MAX( minselecteddate , SELECTEDVALUE('Table'[AssigmentStartDate]))
var enddatevalue = MIN( mAXselecteddate , SELECTEDVALUE('Table'[AssignementFinishDate]))
Return
NETWORKDAYS( startdatevalue, enddatevalue)
 

MFelix_1-1680113010804.png

 

You can then make some adjustements to not get the negative values something similar to:

 

days_ = 
var maxselecteddate = MAX(Calendar[Date])
var minselecteddate = MIN(Calendar[Date])
var startdatevalue = MAX( minselecteddate , SELECTEDVALUE('Table'[AssigmentStartDate]))
var enddatevalue = MIN( mAXselecteddate , SELECTEDVALUE('Table'[AssignementFinishDate]))
var days_total = NETWORKDAYS( startdatevalue, enddatevalue)
Return
IF(days_total > 0 , days_total)

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



pbicom4.PNG

 

Thanks! It did work but now for some reason the values won't add up and give me a total in the table visual shown in the image.

RESTCAP = Workperday*days_

My final goal is to find the total of these three columns. I was getting the sum with@tamerj1 's solution but not with this.

Hi @PMnooBI ,

 

Try the following code:

days_ =
VAR maxselecteddate =
    MAX ( Calendar[Date] )
VAR minselecteddate =
    MIN ( Calendar[Date] )
VAR startdatevalue =
    MAX ( minselecteddate, MIN ( 'Table (2)'[AssignementStartDate] ) )
VAR enddatevalue =
    MIN ( mAXselecteddate, MIN ( 'Table (2)'[AssignementFinishDate] ) )
VAR days_total =
    NETWORKDAYS ( startdatevalue, enddatevalue )
VAR TableValues =
    ADDCOLUMNS (
        'Table (2)',
        "DaysTotal",
            VAR net_days =
                NETWORKDAYS (
                    MAX ( minselecteddate, 'Table (2)'[AssignementStartDate] ),
                    MIN ( mAXselecteddate, 'Table (2)'[AssignementFinishDate] )
                )
            RETURN
                IF ( net_days > 0, net_days )
    )
RETURN
    SUMX ( TableValues, [DaysTotal] )

MFelix_0-1680165096579.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @PMnooBI 

You can work around it:
CALCULATE(COUNT(DAYS), FILTER(DATES, SELECTEDVALUE(DATES(DATE)) >= MIN(DATE) && SELECTEDVALUE(DATES(DATE)) <= MAX(DATE))

 

Dax will be depend on that you are using a date table or not.

tamerj1
Super User
Super User

Hi @PMnooBI 

you may try

=

NETWORKDAYS ( MIN ( 'Date'[Date] ), MAX ( 'Date'[Date] ), 2 )

That just returns the working days by excluding weekends. I need a function to calculate number of days of a task only within a date range.

@PMnooBI 

Which date range? The selected date range or the date range between start and finish dates?

Selected date range. the dates i set in the slicer. Basicaly have to calculate workdays that overlap with slicer date range and the task start and end dates

@PMnooBI 

Hope something like

=
COUNTROWS (
INTERSECT (
CALENDAR (
MAX ( 'Table'[AssignmentSartDate] ),
MAX ( 'Table'[AssignmentFinishDate] )
),
VALUES ( 'Date'[Date] )
)
)

pbicom3.PNGGreat! It does work but it counts the weekends as well. Can the formula be modififed to not include weekends? and also you can see the time is 12:00 a.m. for both slicer date ranges and I think that is why it counts the next day as another one

"Task Days" is the output

@PMnooBI 
Yes, the weekends can be filtered out using

=
COUNTROWS (
    FILTER (
        INTERSECT (
            CALENDAR (
                MAX ( 'Table'[AssignmentSartDate] ),
                MAX ( 'Table'[AssignmentFinishDate] )
            ),
            VALUES ( 'Date'[Date] )
        ),
        NOT ( WEEKDAY ( [Date], 2 ) IN { 6, 7 } )
    )
)

12:00AM is just a different format of 00:00 so I'm not sure if I fully understand what exactly the problem is.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.