Forum Discussion

Rigoleto's avatar
Rigoleto
Helper II
8 years ago
Solved

get value from Previous row

Need a funtion or logic to read a previous row, for instance:

 

 

 

 

 

 

 

 

 

 

How can you see Do I need is to sum up the previos record and build a new column with those values

Appreciate your help!!

 

 

 

  • Rigoleto

     

    I think this calculated column would work.

    See the attached sample file as well

     

    Calculated Column =
    VAR PreviousRow =
        TOPN (
            1,
            FILTER (
                Table1,
                Table1[Month] < EARLIER ( Table1[Month] )
                    && Table1[Employee] = EARLIER ( Table1[Employee] )
            ),
            [Month], DESC
        )
    VAR PreviousValue =
        MINX ( PreviousRow, [Sales] )
    RETURN
        Table1[Sales] + PreviousValue

27 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    Rigoleto

     

    Try this Column

     

    Column =
    VAR PreviousRow =
        TOPN (
            1,
            FILTER ( Table1, Table1[Column A] < EARLIER ( Table1[Column A] ) ),
            [Column A], DESC
        )
    VAR PreviousValue =
        MINX ( PreviousRow, [Column B] )
    RETURN
        Table1[Column B] + PreviousValue
    • Rigoleto's avatar
      Rigoleto
      Helper II

      Hi,

       

      I would like as calculated column, please advise me about the logic , also include as measure if you can

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

         

        In what order should the numbers appear in column B?  Should they be in descending order?

  • Thanks a Lot for you help guys, this is the solution!!!!!

     

    :)

     

    • v-jiascu-msft's avatar
      v-jiascu-msft
      Microsoft Employee

      Hi Rigoleto,

       

      Please mark the right answers by clicking "Accept as Solution".

       

      Best Regards,

      Dale

  • nakul555's avatar
    nakul555
    Frequent Visitor

    Hello Zubair_Muhammad,

    I was trying to do something similar but I have a large dataset (~2M rows) and PBI desktop is unable to process it. It gives me this error. I think it has something to do with 2 earlier statements.

    Is there any other way we could do this?

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Please help me with this matter,

    I need to sum up the current value with the previous month's value. Please help me to get this done in power bi. Appreciate your help.

     

     

    • Ashish_Mathur's avatar
      Ashish_Mathur
      Super User

      Hi,

      Share raw data in a format that can be pasted in an MS Excel file.  Is the FY from Aug - Jul?  If there is multiple years of data, then should the opening balance reset in August? 

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Ashish,

        We are calculating this for the current month onwards. If there are balance values we take it as an opening balance.
        E.g:

        MonthJuly(Opening Balance)AugSepOctNovDecJanFebMar
        Budget Sales 17473641559823281870425475032909010223738025589052017217
        Probable Monthly Receipts - AR8,613,088187899330635312738160.92763420.50000
        Probable Monthly Receipts - Budget Sales 00001559823281870425475032909010
        Exposure 8,481,459  6,977,751  7,058,294  8,842,377  10,191,564  9,610,240  9,621,642  8,729,849 

        Here I want to get a measure for the Exposure row. That's the place I got confused about how to get a previous value and iterate the value over months.

         

         

         

  • zbikra's avatar
    zbikra
    Frequent Visitor

    Hi;

    My problem is a very closed I've find on diff forums, but not exactly the same. So:

     

    I want to calculate [start current daily stock] with the formula: 

    [start current daily stock] of the current day = [start current daily stock] of the previous day + [delivery] of the previous day - [daily consumption] of the previous day.

    Please note that the value of [start current daily stock] for Today comes from an another source, so it's not calculated with the formula than further days.

    Does Anybody to help me to solve my problem ? 

    Thx very mych in advance.