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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
scabbyabbey
Regular Visitor

Number of working days between two dates but using today if no resolved date

I'm using the following to calculate the age of an incident using working days only. It works perfectly for incidents that have a resolved date, but for incidents that don't have a resolved date it is counting non-working days as well. 

 

I have a date table that shows Monday to Friday as 1s for working days, and Saturdays and Sundays as 0. 

 

Can someone point out what wrong here? I'm an absolute novice and pieced this together from other solutions I'd found. 

 

Thank you.

 

INC Age = IF(OR(ISBLANK('SN'[Created.Date1]),ISBLANK('SN'[Resolved.Date1])),
DATEDIFF('SN'[Created.Date1],TODAY(),DAY),
IF(OR
('SN'[Resolved.Date1] < 'SN'[Created.Date1],'SN'[Created.Date1] > 'SN'[Resolved.Date1]),
-1 *CALCULATE(COUNT('DateTable'[IsWorkDay]),FILTER('DateTable','DateTable'[Date] < SN[Created.Date1] && 'DateTable'[Date]>=SN[Resolved.Date1] && 'DateTable'[IsWorkDay] = 1)) + 0,
CALCULATE(COUNT('DateTable'[IsWorkDay]),FILTER('DateTable','DateTable'[Date] >= SN[Created.Date1] && 'DateTable'[Date]<'SN'[Resolved.Date1] && 'DateTable'[IsWorkDay] = 1)))) + 0

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @scabbyabbey,

 

Please try:

INC Age =
IF (
    OR ( ISBLANK ( 'SN'[Created.Date1] ), ISBLANK ( 'SN'[Resolved.Date1] ) ),
    CALCULATE (
        COUNT ( 'DateTable'[IsWorkDay] ),
        FILTER (
            'DateTable',
            'DateTable'[Date] >= SN[Created.Date1]
                && 'DateTable'[Date] < TODAY ()
                && 'DateTable'[IsWorkDay] = 1
        )
    ),
    IF (
        OR (
            'SN'[Resolved.Date1] < 'SN'[Created.Date1],
            'SN'[Created.Date1] > 'SN'[Resolved.Date1]
        ),
        -1
            * CALCULATE (
                COUNT ( 'DateTable'[IsWorkDay] ),
                FILTER (
                    'DateTable',
                    'DateTable'[Date] < SN[Created.Date1]
                        && 'DateTable'[Date] >= SN[Resolved.Date1]
                        && 'DateTable'[IsWorkDay] = 1
                )
            )
            + 0,
        CALCULATE (
            COUNT ( 'DateTable'[IsWorkDay] ),
            FILTER (
                'DateTable',
                'DateTable'[Date] >= SN[Created.Date1]
                    && 'DateTable'[Date] < 'SN'[Resolved.Date1]
                    && 'DateTable'[IsWorkDay] = 1
            )
        )
    )
)
    + 0

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @scabbyabbey,

 

Please try:

INC Age =
IF (
    OR ( ISBLANK ( 'SN'[Created.Date1] ), ISBLANK ( 'SN'[Resolved.Date1] ) ),
    CALCULATE (
        COUNT ( 'DateTable'[IsWorkDay] ),
        FILTER (
            'DateTable',
            'DateTable'[Date] >= SN[Created.Date1]
                && 'DateTable'[Date] < TODAY ()
                && 'DateTable'[IsWorkDay] = 1
        )
    ),
    IF (
        OR (
            'SN'[Resolved.Date1] < 'SN'[Created.Date1],
            'SN'[Created.Date1] > 'SN'[Resolved.Date1]
        ),
        -1
            * CALCULATE (
                COUNT ( 'DateTable'[IsWorkDay] ),
                FILTER (
                    'DateTable',
                    'DateTable'[Date] < SN[Created.Date1]
                        && 'DateTable'[Date] >= SN[Resolved.Date1]
                        && 'DateTable'[IsWorkDay] = 1
                )
            )
            + 0,
        CALCULATE (
            COUNT ( 'DateTable'[IsWorkDay] ),
            FILTER (
                'DateTable',
                'DateTable'[Date] >= SN[Created.Date1]
                    && 'DateTable'[Date] < 'SN'[Resolved.Date1]
                    && 'DateTable'[IsWorkDay] = 1
            )
        )
    )
)
    + 0

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you Yuliana, this worked!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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