Forum Discussion
Reference Previous Value in adjacent column
- 8 years ago
I may be simplifying it, but DAX calculates the whole column at the same time, the visible order in the pivot is not really relevant for the calculation
Regardless - this should work, it looks up the Index that is lower than current index and where price is different than current price= VAR CurrentIndex = INTC[Index] VAR CurrentPrice = INTC[Prices] VAR PreviousIndex = CALCULATE(MAX(INTC[Index]),FILTER(ALL(INTC),AND(INTC[Index]<CurrentIndex,INTC[Prices]<>CurrentPrice))) VAR PreviousPrice = CALCULATE(SUM(INTC[Prices]),FILTER(ALL(INTC),INTC[Index]=MAX(PreviousIndex,1))) //gets previous price VAR Delta = INTC[Prices]-PreviousPrice //calculates the delta RETURN IF(Delta<0,"-",IF(Delta>0,"+",BLANK()))
the problem is IF the price is the same as above (most recent) then use the same symbol. I assume it can work because the formula is working down, so the previous value of the column has already been calculated, not sure why it cant be referenced in the formula for the next row, I dont see a 'circular reference' error, the values are independant. here is a small sequence of how the logic should work. sometimes there are consecutive equal values
IF( current price > previous value), "+", IF( current value < previous price), "-" , use previous value of same column (either ( - or +)
Price, Trade
36.05
36.00, -
35.90, -
35,75, -
35.90, +
35.90, +
35.90, +
35.80, -
35.90, +
I may be simplifying it, but DAX calculates the whole column at the same time, the visible order in the pivot is not really relevant for the calculation
Regardless - this should work, it looks up the Index that is lower than current index and where price is different than current price
= VAR CurrentIndex = INTC[Index] VAR CurrentPrice = INTC[Prices] VAR PreviousIndex = CALCULATE(MAX(INTC[Index]),FILTER(ALL(INTC),AND(INTC[Index]<CurrentIndex,INTC[Prices]<>CurrentPrice))) VAR PreviousPrice = CALCULATE(SUM(INTC[Prices]),FILTER(ALL(INTC),INTC[Index]=MAX(PreviousIndex,1))) //gets previous price VAR Delta = INTC[Prices]-PreviousPrice //calculates the delta RETURN IF(Delta<0,"-",IF(Delta>0,"+",BLANK()))