Forum Discussion

RDA_PowerBI's avatar
RDA_PowerBI
Frequent Visitor
7 years ago
Solved

Calculate Difference Between Previous Row

Hi,

 

I am looking for help calculating the difference between the Numbers column below if  'Table'[Book] = EARLIER ('Table'[Book]) . The column below is what I would need. This would help determine if Numbers were skipped if Column => 1

 

BookNumbersColumn
A10
A21
A53
A83
A91
A123
A153
A161
A171
A258

 

Any help is appreciated.  

 

 

  • Right, so you would subtract the numbers. The intention was to show you how to use MAXX/MINX coupled with EARLIER and other filters to figure out the previous row value that you want to target and then you can use that to calculate what you want.

6 Replies

  • Hi,

     

    Try this calculated column formula

     

    =if(ISBLANK(CALCULATE(MAX(Table1[Numbers]),FILTER(Table1,Table1[Book]=EARLIER(Table1[Book])&&Table1[Numbers]<EARLIER(Table1[Numbers])))),BLANK(),[Numbers]-CALCULATE(MAX(Table1[Numbers]),FILTER(Table1,Table1[Book]=EARLIER(Table1[Book])&&Table1[Numbers]<EARLIER(Table1[Numbers]))))

     

    Hope this helps.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      This is awesome and if you were doing this with dates just substitue with Datediff vs the -. 
      Thanks again!

    • ahsankhan's avatar
      ahsankhan
      Helper I

      Hey thank you for your reply. Is it possible to have a calculated measure for this scenario. As the data i have to deal with contains so many rows and with calculated columns it takes alot of time. And our basic necessity is to reduce the time for the reporting. 

       

      Thank you 

    • RDA_PowerBI's avatar
      RDA_PowerBI
      Frequent Visitor

      I can't use DATEDIFF because there is no date in this case. 

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Right, so you would subtract the numbers. The intention was to show you how to use MAXX/MINX coupled with EARLIER and other filters to figure out the previous row value that you want to target and then you can use that to calculate what you want.