Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Calculate Difference between multiple rows in table

Hi

 

I have a table with two columes, Month and Value. 

I want to create a third column that calculate the difference between the first value (lowest date) and current value.

The measure must be dynamic since the dates is adjustable. (See below where desired result of difference is shown)

 

I try using below dax for mindate but only recieve same date as selected row (e.g. 2302 at row 2302 when I want to recieve 2301 to be able to compare with this basevalue). Do I need to replace "Allselected" with somethingelse?

CALCULATE(min('Date'[MonthSort]),ALLSELECTED('Date'[Date]))

 

Example:

YearMonth   Value  Difference

2301             10       0 (10-10)

2302             12       2 (12-10)

2303             8         -2 (8-10) 

2304             11        1 (11-10)

3 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi CoreyP 

      Unfortunately, that return the same result as Allselected

       

  • Anonymous Use the below Column:

     
    Column =
    VAR Prev = CALCULATE(SUM(MyTable[Value]),FILTER(ALL(MyTable),MyTable[MonthYear]=MIN(MyTable[MonthYear])))
    RETURN MyTable[Value]-Prev