Forum Discussion

Urvashi's avatar
Urvashi
Regular Visitor
5 years ago

DAX Help in Finding NEW Service

Hi

 

I am new to DAX and need help with the below issue. I need to find if a service is new or ongoing based on following conditions.

 

For DP Service - if a customer has received the same service more than once and the difference in (Next Service Start Date - Previous Service End Date) >1, then it's a 'New' service.

 

For HC Service - if a customer has received the same service more than once and the difference in (Next Service Start Date - Previous Service End Date )>7, then it's a 'New' service.

 

I need to produce result as shown below.

 

 

Customer IDService TypeStart DateEnd DateRankxDuplicate CountRESULT
21563DP17/06/2019 12New
21563DP03/04/2020 22New
21563HC19/01/201706/01/201913New
21563HC07/01/201901/04/202023 
21563HC03/04/2020 33 
89326DP21/01/201918/07/201912New
89326DP19/07/201922/08/201922 
89326HC18/06/201622/08/201912New
89326HC05/09/201931/12/201922New

 

 

Thanks in advance.

 

2 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    Urvashi 

    Result :=
    VAR _CurrentStartDate =
        MAX ( Table2[Start Date] )
    VAR _PreviousStartDate =
        CALCULATE (
            MAX ( Table2[Start Date] ),
            Table2[Start Date] < _CurrentStartDate,
            ALLEXCEPT ( Table2, Table2[Customer ID], Table2[Service Type] )
        )
    VAR _PreviousEndDate =
        CALCULATE (
            MAX ( Table2[End Date] ),
            Table2[Start Date] = _PreviousStartDate,
            ALLEXCEPT ( Table2, Table2[Customer ID], Table2[Service Type] )
        )
    VAR _CurrentType =
        MAX ( Table2[Service Type] )
    RETURN
        IF (
            _CurrentStartDate - _PreviousEndDate
                > IF ( _CurrentType = "PD", 1, 7 ),
            "New"
        )