Forum Discussion
Need help in creating calculated column based on the same column previous row
- 1 year ago
Hello Anonymous
Power Query allows you to refer to previous rows, which is ideal here.
Steps
Sort your data by Dt and Level (or another stable ordering).
- Add an Index column.
- Add a custom column to compute the value based on the previous row.
- Use logic like
Custome= if [Index] = 0 then 0
else [Target] - #"Previous Step"{[Index]-1}[NewColumn]
for DAX Measure
New Measure =
VAR CurrentIndex = MAX('Table'[Index])
VAR PrevIndex = CurrentIndex - 1
VAR PrevValue =
CALCULATE(
MAX('Table'[YourTarget]),
FILTER('Table', 'Table'[Index] = PrevIndex)
)
RETURN
[Target] - PrevValue
Thanks,
Pankaj Namekar | LinkedInIf this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
Very confusing. The value in the second row is 14 (not 40). Where does 40 come from?
40 is the additional calculation value - previous row value.