Forum Discussion
drewswiney
5 years agoRegular Visitor
Dynamically Reference Calculated Row Above
Hello. I am looking to create column D of the table below in power query. You can see the excel formula to the right. I need to add columns from the current row and add a previously calculated row ab...
- Anonymous5 years ago
Hi drewswiney
Add a helpColumn and an Index column
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY7JDYAwDARbQXmvhO3gI7Wg9EYtVEYAKZza1zxm7HlOpCPxKCSckNZl3xAECb+4GCYund8bWAPilipaz749d2TRW99gSo1Pw38+yHDLD2Yv3YgfgxGFbjcnkOth1A0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Production = _t, Demand = _t, Orignal = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Production", Int64.Type}, {"Demand", Int64.Type}, {"Orignal", Int64.Type}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type), #"Added Custom" = Table.AddColumn(#"Added Index", "helpColumn", each if [Index]=0 then [Orignal] else [Production]- [Demand]), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Final Inventory", each List.Sum(List.FirstN(#"Added Custom"[helpColumn],[Index]+1))) in #"Added Custom1"
Anonymous
5 years agoNot applicable
Hi drewswiney
Add a helpColumn and an Index column
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY7JDYAwDARbQXmvhO3gI7Wg9EYtVEYAKZza1zxm7HlOpCPxKCSckNZl3xAECb+4GCYund8bWAPilipaz749d2TRW99gSo1Pw38+yHDLD2Yv3YgfgxGFbjcnkOth1A0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Production = _t, Demand = _t, Orignal = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Production", Int64.Type}, {"Demand", Int64.Type}, {"Orignal", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "helpColumn", each if [Index]=0 then [Orignal]
else [Production]- [Demand]),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Final Inventory", each List.Sum(List.FirstN(#"Added Custom"[helpColumn],[Index]+1)))
in
#"Added Custom1"