Forum Discussion
marsclone
3 years agoHelper IV
Calculate next row minus current row?
I've searched, but didn't find the answer on this question? I want to calculate the next value minus the current value from the column "Breken VSI totaal". Is that possible? All columns are mea...
adudani
3 years agoMemorable Member
hi marsclone ,
create a blank query and copy paste the following code in the advanced editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NU5BDsMwDPpLzpVlp0mbHNdu7f5Q5f/fGDjeARAGIT9POrSmJb2AVRpYxYLHwnSDOwC2spTgme1wJ0Ct0oNnxq03YCrblPaXWWD9w7komHAmZ4gXTGEvrhd/qRUvQGLBeL15qp70JnnKGgXaLwu7L/TuP5pqGuMH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Nr = _t, GradTIE = _t, #"%Zeef total" = _t, #"BreKen Vsi" = _t, #"BreKen Vsi total" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Nr", type text}, {"GradTIE", type text}, {"%Zeef total", type number}, {"BreKen Vsi", type number}, {"BreKen Vsi total", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Prev Row Difference" = Table.AddColumn(#"Added Index", "Result_", each try
#"Added Index" {[Index] -1 }[BreKen Vsi total]
otherwise
null),
#"Added Custom" = Table.AddColumn(#"Prev Row Difference", "Result", each try
#"Prev Row Difference" {[Index] +1 }[[Result_]]
otherwise
null),
#"Expanded Result" = Table.ExpandRecordColumn(#"Added Custom", "Result", {"Result_"}, {"Result_.1"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Result",{"Index", "Result_"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Result_.1", type number}})
in
#"Changed Type1"
let me know if this is an acceptable solution.
for reference: (8) Refer to Previous Row in Power BI - YouTube
Appreciate a thumbs up if this is helpful.