Forum Discussion
Anonymous
1 year agoNot applicable
Need help in creating calculated column based on the same column previous row
Hi, I have a table as mentioned below without New Column, I want to create a calculated column as New Column on 1st row initial value as ZERO(for L1) by default, but second row that L2 40-0 (40 is t...
- 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.
Anonymous
1 year agoNot applicable
It has to be done at calculated column only.