Forum Discussion

Hart1969's avatar
Hart1969
Regular Visitor
3 years ago
Solved

Power Query: Computing a value of a column based on the previous value of the same column

Hello, i have the following problem and need a solution to solve it with Power Query: Ich have different Releases (22.1, 22.2, 22.3 , 22.4, 23.1, 23.2, 23.3, 23.4) In each release i the given the ...
  • lbendlin's avatar
    3 years ago

    Power Query has no concept of "previous".  You need to indicate what that means in your scenario, ideally by adding an index column. You can drop the columns that are not part of the issue.

     

    From there it is a standard List.Accumulate to calculate the backlog value:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLSM1TSUTI2BREGSrE6YCEjIM/EAEXIGMgzQhUyAfIMkYWMwWaZmKIIGUF4yEJgs1BVoZgVCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Release = _t, #"Needed Capacity" = _t, #"Available Capacity" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Needed Capacity", Int64.Type}, {"Available Capacity", Int64.Type}}),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
        #"Added Custom" = Table.AddColumn(#"Added Index", "Backlog", each List.Accumulate({0..[Index]},0,(state,current)=> List.Max({0, state + #"Added Index"[Needed Capacity]{current}-#"Added Index"[Available Capacity]{current}})))
    in
        #"Added Custom"