Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
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 ID | Service Type | Start Date | End Date | Rankx | Duplicate Count | RESULT |
| 21563 | DP | 17/06/2019 | 1 | 2 | New | |
| 21563 | DP | 03/04/2020 | 2 | 2 | New | |
| 21563 | HC | 19/01/2017 | 06/01/2019 | 1 | 3 | New |
| 21563 | HC | 07/01/2019 | 01/04/2020 | 2 | 3 | |
| 21563 | HC | 03/04/2020 | 3 | 3 | ||
| 89326 | DP | 21/01/2019 | 18/07/2019 | 1 | 2 | New |
| 89326 | DP | 19/07/2019 | 22/08/2019 | 2 | 2 | |
| 89326 | HC | 18/06/2016 | 22/08/2019 | 1 | 2 | New |
| 89326 | HC | 05/09/2019 | 31/12/2019 | 2 | 2 | New |
Thanks in advance.
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"
)
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/
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 23 | |
| 12 | |
| 11 | |
| 9 | |
| 8 |