Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
4 years ago
Solved

Calculate between rows

Good afternoon Surely it is a very simple problem, but I do not find the right solution. I have a database, which brings me a record of samples as shown in the table. Date Name Code Va...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Syndicate_Admin ,

     

    Please refer this formula:

    cons water = 
    var last_date = CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Date]<EARLIER('Table'[Date])&&'Table'[Code]=2235))
    var last_value = CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Date]=last_date&&'Table'[Code]=2235))
    return
    IF(ISBLANK(last_value),BLANK(),IF('Table'[Code]=2235,'Table'[Value]-last_value))

    For [Cons Elect] and [Cons gas], just need to replace the 'Table'[Code] in the formula.

    Result:

     

    Best Regards,

    Jay