Forum Discussion

dm1904's avatar
dm1904
Helper I
7 years ago
Solved

Calculating Difference Between Current and last Values (By Date) and Divide by Date Diff

Hi, I occasionally spend many hours trying to solve something without success. And on these occasions I have to turn to the good people of the PBI community. Hoping somebody out there has come accros...
  • v-jiascu-msft's avatar
    7 years ago

    Hi dm1904,

     

    I assume the dates are in order. Please download the demo from the attachment. You should reconsider which days to use, 18 or 19.

    ForecaseNew =
    VAR currentPackage = [Package]
    VAR currentDate = [Date]
    VAR lastdateHasFC =
        CALCULATE (
            MAX ( Table1[Date] ),
            FILTER (
                Table1,
                Table1[Package] = currentPackage
                    && Table1[Date] < currentDate
                    && Table1[Forecast] > 0
            )
        )
    VAR nextdateHasFC =
        CALCULATE (
            MIN ( Table1[Date] ),
            FILTER (
                Table1,
                Table1[Package] = currentPackage
                    && Table1[Date] > currentDate
                    && Table1[Forecast] > 0
            )
        )
    VAR lastForecast =
        CALCULATE (
            MAX ( Table1[Forecast] ),
            FILTER (
                Table1,
                Table1[Package] = currentPackage
                    && Table1[Date] = lastdateHasFC
            )
        )
    VAR nextForecast =
        CALCULATE (
            MAX ( Table1[Forecast] ),
            FILTER (
                Table1,
                Table1[Package] = currentPackage
                    && Table1[Date] = nextdateHasFC
            )
        )
    VAR newForecast =
        lastForecast
            + DIVIDE (
                nextForecast - lastForecast,
                DATEDIFF ( lastdateHasFC, nextdateHasFC, DAY )
            )
                * DATEDIFF ( lastdateHasFC, currentDate, DAY )
    RETURN
        IF ( ISBLANK ( [Forecast] ), newForecast, Table1[Forecast] )
    

    Calculating-Difference-Between-Current-and-last-Values-By-Date-and-Divide-by-Date-Diff

     

     

    Best Regards,