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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ConfusedTime
Frequent Visitor

Overlapping Dates and Service Type

Hi Everyone,

 

I'm after some help if possible, I've been through previous posts and I'm stuck! 

 

I'm trying to identify an overlap in services by date and service type, so for example this would return client 1 as they are accessing 2 different services at the same time:

 

service table

ClientID    Start Date    End Date   Service

1                1/1/22         31/1/22     A 

2                3/3/18        15/3/18      A

2                4/3/18         5/3/13       A

3                10/10/22                      C

1                 30/1/22        5/2/22    B

 

Not all records have an end date and the table can have multiple entries for each client.

 

Any pointers, hints or tips will be a massive help as I'm lost - thanks in advance!

1 ACCEPTED SOLUTION

Hi @ConfusedTime ,

You can create a calculated column as below to get it:

Flag = 
CALCULATE (
    DISTINCTCOUNT ( 'Service'[Service] ),
    FILTER (
        'Service',
        [ClientID] = EARLIER ( [ClientID] )
            && 'Service'[Start Date] > EARLIER ( 'Service'[Start Date] )
            && 'Service'[Start Date] <= EARLIER ( 'Service'[End Date] )
            && 'Service'[Service] <> EARLIER ( 'Service'[Service] )
    )
)

vyiruanmsft_0-1690956282338.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

8 REPLIES 8
ConfusedTime
Frequent Visitor

Hi,

Sorry for the late reply, it doesn't seem to be working for me, I get a massive long number back? 

I've filtered my table to have only 2 service types and put it in your PBI example and get the same result.

 I have this working to count overlapping dates (taken from another post) but I need it to only count the overlapping date when the service is different - can I add yours in to this somehow? Sorry I'm not very good with DAX/variables.  My table is now filtered to be only 2 different types of services.

Thanks

 

Overlapping Date =
VAR NewTable =
    ADDCOLUMNS (
        'Service',
        "Service", COUNTROWS (
            FILTER (
                ALL ('Service' ),
                [ClientID] = EARLIER ( [ClientID] )
                    && 'Service' [Start Date] < EARLIER ( 'Service'[End Date])
                    && 'Service'[End Date]> EARLIER ( 'Service' [Start Date])
                    && NOT (
                        'Service'[End Date] = EARLIER ( 'Service'[End Date] )
                            && 'Service' [Start Date] = EARLIER ( 'Service' [Start Date])
                    )
            )
        )
    )
RETURN
    SUMX ( GROUPBY ( NewTable, [ClientID], [Overlapping] ), [Overlapping] )

Hi @ConfusedTime ,

What's your expected result? Do you want to get the count of IDs or the IDs which fulfill the conditions? Could you please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

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.

Thanks for your reply.  I'm hoping to be able to give a count of overlaps, plus identify who they are so they can be followed up. 

I've attached a sample of data, in this example it would highlight 4 overlaps of service (highlighted blue). 

Thanks for all your help!

ClientIDServiceStart DateEnd Date
11111Service A18/11/201826/11/2018
11111Service A11/05/2019 
11111Service A19/06/202110/07/2021
11131Service A27/12/201616/06/2017
11131Service B13/06/201723/09/2017
11131Service A24/09/201721/07/2018
11131Service A22/07/201802/10/2018
11131Service A14/12/202004/01/2021
11131Service A03/01/2021 
11222Service A10/08/201324/11/2013
11222Service A10/08/201306/04/2014
11222Service A21/11/201306/04/2014
11222Service B07/04/201417/02/2015
18888Service A11/04/201109/03/2014
18888Service A10/03/201417/08/2014
26262Service A16/09/201311/10/2013
26262Service B12/10/202020/10/2020
26262Service A18/10/202001/11/2020
91919Service A18/03/201302/09/2013
91919Service A07/04/201412/10/2016
91919Service B10/10/2016 
99991Service A24/10/2019 
99991Service A07/12/202025/06/2021
99991Service B25/06/202102/07/2021
99991Service A03/07/202114/09/2021
99991Service A26/01/202214/09/2022

Hi @ConfusedTime ,

You can create a calculated column as below to get it:

Flag = 
CALCULATE (
    DISTINCTCOUNT ( 'Service'[Service] ),
    FILTER (
        'Service',
        [ClientID] = EARLIER ( [ClientID] )
            && 'Service'[Start Date] > EARLIER ( 'Service'[Start Date] )
            && 'Service'[Start Date] <= EARLIER ( 'Service'[End Date] )
            && 'Service'[Service] <> EARLIER ( 'Service'[Service] )
    )
)

vyiruanmsft_0-1690956282338.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.

This works perfectly! Thank you so much for all you help! 😊

ConfusedTime
Frequent Visitor

Brill, thank you! I'll test it out and get back to you..thanks again!

Hi @ConfusedTime ,

Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.

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.
v-yiruan-msft
Community Support
Community Support

Hi @ConfusedTime ,

You can create a measure as below to get it:

 

Clients with multiple services = 
VAR _tab =
    SUMMARIZE (
        'service',
        'service'[ClientID],
        "@count",
            CALCULATE (
                DISTINCTCOUNT ( service[Service] ),
                ALLEXCEPT ( 'service', 'service'[ClientID] )
            )
    )
RETURN
    CONCATENATEX ( FILTER ( _tab, [@count] > 1 ), [ClientID], "," )

 

vyiruanmsft_0-1690340431868.png

If the above one is not what you want, could you please provide your expected result with the detailed calculation logic and specific examples? It would be helpful to find the solution. Thank you.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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