Power BI refer to previous row
Last updated
Was this helpful?
Last updated
Was this helpful?
sample data
Formula is like:
result =
if [previous row exists]:
(last(target) - first(target))/11 + <previous row value>
else:
first(target)
In PowerBI we cannot refer to self (e.g. previous row same column), but can refer to previous row another column.
So we can make kind of math transformation:
row0 = 1.7
row1 = (2.15 - 1.7)/11 + 1.7
row2 = (2.15 - 1.7)/11 + row1 = (2.15 - 1.7)/11 * 2 + 1.7
row3 = (2.15 - 1.7)/11 + row2 = (2.15 - 1.7)/11 * 3 + 1.7
...
The transformed formula:
result =
(last(target) - first(target))/11 * <index of row> + first(target)
Load Data
Add Index Column
Add Custom Column 'result', make formula:
( List.Last(#"Added Index" [target]) - List.First(#"Added Index" [target]))/11 * #"Added Index" {[Index]}[Index] + List.First(#"Added Index" [target])
the
List.Last
can be replace byList.Max
, andList.First
can be replaced byLits.Min
regard of context.
Final Result: