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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Calculating date difference in the same column for different categories

Hi,
I have tried looking through the forums, and while there are similar queries there aren't any answers that I have been able to directly apply.  I am trying to work out the days overdue for each service (School/setting, CCP, EP) from the received date - due date.  The other date differences are less of a concern.  

ym907182_4-1675266782786.png

 

The complexity is they relate to different cases, and different services with different stages in.

I have tried a calculated column, but I am not very experienced with DAX: 

ym907182_1-1675266039923.png


Please could you help with the DAX, or to suggest another method, e.g. how to create a measure for this?

Thanks,

Dan

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

Please update the formula of calculated column [DateDiff] as below to get the correct datediff, you can find the details in the attachment.

Datediff = 
VAR _DueDate =
    CALCULATE (
        MAX ( 'Prof Reports and Panel - EHCP004'[Date] ),
        FILTER (
            ALLEXCEPT (
                'Prof Reports and Panel - EHCP004',
                'Prof Reports and Panel - EHCP004'[Case Number]
            ),
            'Prof Reports and Panel - EHCP004'[Stage index] = 1
        )
    )
VAR _ReceivedDate =
    CALCULATE (
        MAX ( 'Prof Reports and Panel - EHCP004'[Date] ),
        FILTER (
            ALLEXCEPT (
                'Prof Reports and Panel - EHCP004',
                'Prof Reports and Panel - EHCP004'[Case Number]
            ),
            'Prof Reports and Panel - EHCP004'[Stage index] = 2
        )
    )
RETURN
   DATEDIFF ( _DueDate, _ReceivedDate, DAY )

yingyinr_0-1675305084762.png

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

Please update the formula of calculated column [DateDiff] as below to get the correct datediff, you can find the details in the attachment.

Datediff = 
VAR _DueDate =
    CALCULATE (
        MAX ( 'Prof Reports and Panel - EHCP004'[Date] ),
        FILTER (
            ALLEXCEPT (
                'Prof Reports and Panel - EHCP004',
                'Prof Reports and Panel - EHCP004'[Case Number]
            ),
            'Prof Reports and Panel - EHCP004'[Stage index] = 1
        )
    )
VAR _ReceivedDate =
    CALCULATE (
        MAX ( 'Prof Reports and Panel - EHCP004'[Date] ),
        FILTER (
            ALLEXCEPT (
                'Prof Reports and Panel - EHCP004',
                'Prof Reports and Panel - EHCP004'[Case Number]
            ),
            'Prof Reports and Panel - EHCP004'[Stage index] = 2
        )
    )
RETURN
   DATEDIFF ( _DueDate, _ReceivedDate, DAY )

yingyinr_0-1675305084762.png

Best Regards

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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.