Forum Discussion

bobbrow's avatar
bobbrow
Microsoft Employee
4 years ago
Solved

Comparing two rows in a dataset

I have a table with some values that I want to compare across rows (specifically, I want to tell the percent difference between them by Month).  Here is a sample table with what I'm talking about.  ...
  • Greg_Deckler's avatar
    4 years ago

    bobbrow You could use the YEAR and MONTH functions to ensure that rows are in the same month. Basically what you have is the MTBF pattern. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
    The basic pattern is:
    Column = 
      VAR __Current = [Value]
      VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

      VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
    RETURN
      __Current - __Previous