Forum Discussion

learning_going's avatar
learning_going
Frequent Visitor
2 years ago
Solved

date gap between multiple item for occurrence in different month

hi all   whats the formula to calculate the days gap between each of the entry?   line1: nov 4  to nov 11 line2: nov11  to nov 27 line3:  nov27 to Dec 1  
  • Ritaf1983's avatar
    2 years ago

    Hi learning_going 
    The first step is to add an index column from PQ (after sorting the table by the column of the wanted date)

    after you have an index column you can use a formula like : (replace parameters to the yours)

    Difference =
    VAR CurrentRowIndex = 'Orders'[Index]
    VAR CurrentOrderDate = 'Orders'[Order Date]
    VAR PreviousOrderDate =
        CALCULATE(
            MAX('Orders'[Order Date]),
            FILTER(
                'Orders',
                'Orders'[Index] < CurrentRowIndex
            )
        )
    RETURN
        IF(
            ISBLANK(PreviousOrderDate),
            0,
            DATEDIFF(PreviousOrderDate, CurrentOrderDate, DAY)
        )
    Result :

    PBIX with the example is attached

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