Forum Discussion
EiliseH
1 year agoRegular Visitor
PowerQuery Cumulative/Running Total with less than condition on Date
Hello, I'm hoping someone here can help. I have a data set which records how much is spent per week on each project by each role in each stage of work. In PowerQuery (not DAX), I want to add a cum...
- 1 year ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlHSUQrKz0kFUsEliekgOjw1Nds1LyUzLx3Ica0oSAWyS0qLUj3zQDJKsTrRSo5AGbfEw8sTU1IVggtSkzMTczKLS2BmKJgAWQbm+kBkZGAE4hgbGBgQq9HQhEyNRobkarQgQ6MpukYjEjQaAP1oQY6NhoZIGg2RNToWJWdklkAiFEdgGhFUjhKEhlDlTkTEmQWSs0wNiNdoZIrNP0RoNAC61BKm0YwEfRZI+kxA+mIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t]), #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ExpenditureInWeek", Currency.Type}, {"WeekEnding", type date}},"en-GB"), #"Added Custom" = Table.AddColumn(#"Changed Type", "CumulativeExpenditure", (k)=> List.Sum(Table.SelectRows(#"Changed Type", each [Project]=k[Project] and [Role]=k[Role] and [Stage]=k[Stage] and [WeekEnding]<=k[WeekEnding])[ExpenditureInWeek]),Currency.Type) in #"Added Custom"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.