Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HansPeterPfister/870139f30ad8b0ad3c03e2b52c26179c to your computer and use it in GitHub Desktop.
Save HansPeterPfister/870139f30ad8b0ad3c03e2b52c26179c to your computer and use it in GitHub Desktop.
// Code written by Hans Peter Pfister, www.powerbi-pro.com
let
Source = StockMovements,
Calc_Running_Total = Table.Group(
Source, // table as table
{"Product"}, // key as any
// aggregatedColumns as list
{{"Data", // name of new column to be created
// Function Call
(Input as table) as table => // data for function
let
Call_Function = fn_cumulative_Total_en(Input),
// End of Function Call
result = Table.FromColumns( // putting all together
Table.ToColumns(Input)&{Call_Function},
Value.Type(
Table.AddColumn(
Input, "Saldo", each null, type number
)
)
)
in
result,
type table}} // transform into table
),
#"Expanded Data" = Table.ExpandTableColumn(Calc_Running_Total, "Data", {"Date", "Amount", "Saldo"}, {"Date", "Amount", "Total"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Data",{{"Product", type text}, {"Date", type date}, {"Amount", Int64.Type}, {"Total", Int64.Type}})
in
#"Changed Type"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment