Forum Discussion

redhughes's avatar
redhughes
Helper II
6 years ago
Solved

Detecting gaps

We have a database of communication forms from our clients that holds the forms' start and end dates:   Client Start End John Smith 01/06/2020 30/06/2020 Jane Smith 01/06/2020 30/06/...
  • tex628's avatar
    6 years ago

    This column returns the gap between the current row and the most recent communication of the same client.  

    Column = 
    VAR Name_ = Query1[Client]
    VAR End_ = Query1[End]
    VAR Start_ = Query1[Start]
    VAR Gap = Start_ - CALCULATE(MAX(Query1[End]) , ALL(Query1) , Query1[End] < Start_ , Query1[Client] = Name_) -1
    Return 
    Gap


    Br,
    J



     

     

  • v-deddai1-msft's avatar
    6 years ago

    Hi redhughes ,

     

    Just use the measure below:

     

     

    Measure =
    VAR start_ =
        MAX ( 'Table'[Start] )
    VAR lastend_ =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Client] = MAX ( 'Table'[Client] )
                    && 'Table'[End] <= start_
            ),
            'Table'[End]
        )
    RETURN
        IF (
            DATEDIFF ( lastend_, start_, DAY ) > 1,
            lastend_ + 1 & "-" & start_ - 1 & "gap",
            "No Gap"
        )

     

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    Best Regards,

    Dedmon Dai