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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Urvashi
Regular Visitor

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 2
wdx223_Daniel
Super User
Super User

@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"
    )

wdx223_Daniel_0-1606040869487.png

 

MattAllington
Community Champion
Community Champion

This is actually quite complex, but it has been solved before. I have followed this pattern and it works as advertised. https://www.daxpatterns.com/new-and-returning-customers/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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