Forum Discussion

nasbkrv's avatar
nasbkrv
Regular Visitor
6 years ago
Solved

Previous row value formula

Hi Team,

I read this post: https://community.powerbi.com/t5/Desktop/Calculated-column-From-To-formula/td-p/1274376 and it works for me too, but not for every row.

The given example is:


And the suggested formula is: From =
CALCULATE(SUM('Table'[Metric]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date]<EARLIER('Table'[Date])))+0
With this formula if the ID is the same, the “From’ column is zero for the first result and then it’s the same as “To” field. In my case I have two rows with the same ID, but on the same date (not different dates as in the example). If the ID is new, the From field should start again with 0. The result I’m looking for is:

 



  • Hi nasbkrv ,

     

    Please add an Index column in Power Query Editor first. And then, create calculated columns like so:

    From =
    CALCULATE (
        SUM ( 'Table'[Metric] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            'Table'[Index] < EARLIER ( 'Table'[Index] )
        )
    ) + 0
    
    To =
    'Table'[From] + 'Table'[Metric]
    

     

    Best Regards,

    Icey

     

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

4 Replies