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
RJS22
New Member

Networking Days based on Slicer or values in a table

I am looking at anylsing absence.
For each absence there is a start and end date (some end dates are blank).
We also have a slicer (linked to a date table) with a start and end date for the report.
When the slicer start and end dates are set I want to count the Network days of absence between those 2 dates. 
In explaination - include all absences the are occuring during the slicer date range (those that start before or during the date range but end during or after it) but only count the networking days between the two dates
 For Example.
I have an absence that runs from 18th July 2025 to 23rd July 2025. The slicer is set for the  21st to 25th of July.
The networkdays calculation needs to start on the 21st July (start of the slicer range) and end of the 23rd (end of the absence).
Similarly if an absence ends after the slicer end date the end date should be the slicer end date.

See below the filter has been set for the 14th to the 16th June.
Shown below are the absence start and end dates the start and end date used in the networking days calc and the total.
For the individual rows it is calculating ok ,for the total I would like it to add up the individual network days.

RJS22_1-1753802119251.png

My measure looks like -

Networking Days =
VAR CalendarStartDateMIN ( DateTable[Date] )
VAR CalendarEndDateMAX ( DateTable[Date] )
VAR DealBlankEndDate = IF(MIN('Staff Absences'[Absence End Date]) = BLANK(),
CalendarEndDate, MIN('Staff Absences'[Absence End Date]))
VAR Days = SUMX(FILTER('Staff Absences',   'Staff Absences'[Absence End Date] = BLANK()
   && 'Staff Absences'[Absence Start Date] <= CalendarEndDate
  ||
   'Staff Absences'[Absence End Date] >= CalendarStartDate
   && 'Staff Absences'[Absence Start Date] <= CalendarEndDate
   ),
NETWORKDAYS(
    MAX(CalendarStartDate,'Staff Absences'[Absence Start Date]),
    MIN(CalendarEndDate,DealBlankEndDate)
    , 1
    , 'Bank Holidays'
))
RETURN
IF(ISBLANK(Days),0,Days)
Absence Start DateAbsence End DateAbsence TypeIndex
Mon 12 Jun 202312-Jun-23Sickness510
Fri 16 Jun 202316-Jun-23Other paid authorised absence, e.g. compassionate leave504
Fri 16 Jun 202316-Jun-23Other paid authorised absence, e.g. compassionate leave505
Fri 16 Jun 202316-Jun-23Other paid authorised absence, e.g. compassionate leave506
Thu 15 Jun 202315-Jun-23Other paid authorised absence, e.g. compassionate leave507
Thu 15 Jun 202315-Jun-23Other paid authorised absence, e.g. compassionate leave508
Mon 12 Jun 202323-Jun-23Sickness 
 
MTIA

 

 

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

I think you are close to the solution.

 

Reference:

https://www.daxpatterns.com/events-in-progress/

 

Networking Days =
VAR CalendarStartDate = MIN(DateTable[Date])
VAR CalendarEndDate = MAX(DateTable[Date])
VAR Days =
    SUMX(
        FILTER(
            'Staff Absences',
            (
                ISBLANK('Staff Absences'[Absence End Date])
                    && 'Staff Absences'[Absence Start Date] <= CalendarEndDate
            )
            || (
                'Staff Absences'[Absence End Date] >= CalendarStartDate
                    && 'Staff Absences'[Absence Start Date] <= CalendarEndDate
            )
        ),
        VAR StartDate = MAX(CalendarStartDate, 'Staff Absences'[Absence Start Date])
        VAR EndDate =
            IF(
                ISBLANK('Staff Absences'[Absence End Date]),
                CalendarEndDate,
                MIN(CalendarEndDate, 'Staff Absences'[Absence End Date])
            )
        RETURN
            NETWORKDAYS(StartDate, EndDate, 1, 'Bank Holidays')
    )
RETURN
    IF(ISBLANK(Days), 0, Days)

 

See if this works for you, then we can tweak for little more simpler Dax code ... 

View solution in original post

2 REPLIES 2
sevenhills
Super User
Super User

I think you are close to the solution.

 

Reference:

https://www.daxpatterns.com/events-in-progress/

 

Networking Days =
VAR CalendarStartDate = MIN(DateTable[Date])
VAR CalendarEndDate = MAX(DateTable[Date])
VAR Days =
    SUMX(
        FILTER(
            'Staff Absences',
            (
                ISBLANK('Staff Absences'[Absence End Date])
                    && 'Staff Absences'[Absence Start Date] <= CalendarEndDate
            )
            || (
                'Staff Absences'[Absence End Date] >= CalendarStartDate
                    && 'Staff Absences'[Absence Start Date] <= CalendarEndDate
            )
        ),
        VAR StartDate = MAX(CalendarStartDate, 'Staff Absences'[Absence Start Date])
        VAR EndDate =
            IF(
                ISBLANK('Staff Absences'[Absence End Date]),
                CalendarEndDate,
                MIN(CalendarEndDate, 'Staff Absences'[Absence End Date])
            )
        RETURN
            NETWORKDAYS(StartDate, EndDate, 1, 'Bank Holidays')
    )
RETURN
    IF(ISBLANK(Days), 0, Days)

 

See if this works for you, then we can tweak for little more simpler Dax code ... 

FBergamaschi
Solution Sage
Solution Sage

Can you please show the data model and the detail of the visual settings? I am not sure I understand how you involve the calendar table into the visual

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

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