Overlapping Date Beast Mode

Hi everyone! For context, I am making a card that flags overlapping contract dates. I want to make sure that the first order finishes its duration first before having another order. I only want to partition the overlap flag by customer and by the same business unit. Please see the Excel visualization sample I made below. Can anyone help on my beast mode for the Overlap? Thank you!

Best Answer

  • ColemenWilson
    Answer ✓

    I approached this using Magic ETL, and here is how I did it:

    1. Create a Lead and Lag function to get the previous End Date and the upcoming Start Date.

    2. Create a formula to flag when there is overlap. (also by creating this I noticed that your data in the excel screenshot for overlap appears wrong. For Customer ABC there is overlap with order number 3 ending 12/30/2025 and order number 4 starting 1/1/2025)

    If I solved your problem, please select "yes" above

Answers

  • ColemenWilson
    Answer ✓

    I approached this using Magic ETL, and here is how I did it:

    1. Create a Lead and Lag function to get the previous End Date and the upcoming Start Date.

    2. Create a formula to flag when there is overlap. (also by creating this I noticed that your data in the excel screenshot for overlap appears wrong. For Customer ABC there is overlap with order number 3 ending 12/30/2025 and order number 4 starting 1/1/2025)

    If I solved your problem, please select "yes" above

  • ArborRose
    ArborRose Coach
    edited December 16

    I think you are getting confused by your data. The answers to your data would not be what you show. Your last record overlaps but your display says it doesn't. I did it using SQL Dataflow.

    SELECT
    a.order_number,
    a.customer,
    a.business_unit,
    CASE
    WHEN a.start_date < b.end_date AND a.end_date > b.start_date THEN 'Yes'
    ELSE 'No'
    END AS overlap_flag
    FROM overlap_test a
    JOIN overlap_test b
    ON a.customer = b.customer
    AND a.business_unit = b.business_unit
    AND a.order_number != b.order_number
    ORDER BY a.order_number;

    But to get the answer you show, I had to change the record date on the last record so it wouldn't overlap.

    customer

    order_number

    business_unit

    start_date

    end_date

    xyz

    1

    BU1

    1/1/2023

    12/31/2024

    xyz

    2

    BU1

    12/29/2024

    12/30/2025

    abc

    3

    BU2

    12/29/2024

    12/30/2025

    abc

    4

    BU2

    1/1/2026

    12/31/2026

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **