Forum Discussion
Recreating CALCULATE/SUM/EARLIER within Power Query Editor
- 2 years ago
See this blog post
Create Running Totals in Power Query (excelguru.ca)
Without looking at your data, best way to replicate your DAX measure in Power Query would look something like this...
let // Replace this with your source step Source = YourSourceTableName, // Sort by Date SortedTable = Table.Sort(Source, {{"Date", Order.Ascending}}), // Filter rows where "Delivery Risk" is "Implemented" FilteredTable = Table.SelectRows(SortedTable, each [Delivery Risk] = "Implemented"), // Add a custom column for running total RunningTotal = Table.AddColumn(FilteredTable, "Running Total", each List.Sum(List.FirstN(FilteredTable[Savings per month], [Index] + 1))), // Add an index column for use in the running total calculation AddedIndex = Table.AddIndexColumn(RunningTotal, "Index", 0, 1, Int64.Type) in AddedIndex - 2 years ago
Hi,
one solution could be:
1. Sort the date coulmn Ascending
2. create an Index column strating from 1
3. use the fx button to add a step with the following code:
= Table.AddColumn(
#"Added Index",
"Running Total",
(OutTable) =>
List.Sum(
Table.SelectRows(
#"Added Index",
(InTable) => InTable[Index] <= OutTable[Index]
and
InTable[Delivery Risk] = OutTable[Delivery Risk])[Savings per month]
)
)If I answered your question, please mark my post as solution, Appreciate your Kudos 👍
See this blog post
Create Running Totals in Power Query (excelguru.ca)
Without looking at your data, best way to replicate your DAX measure in Power Query would look something like this...
let
// Replace this with your source step
Source = YourSourceTableName,
// Sort by Date
SortedTable = Table.Sort(Source, {{"Date", Order.Ascending}}),
// Filter rows where "Delivery Risk" is "Implemented"
FilteredTable = Table.SelectRows(SortedTable, each [Delivery Risk] = "Implemented"),
// Add a custom column for running total
RunningTotal = Table.AddColumn(FilteredTable, "Running Total", each List.Sum(List.FirstN(FilteredTable[Savings per month], [Index] + 1))),
// Add an index column for use in the running total calculation
AddedIndex = Table.AddIndexColumn(RunningTotal, "Index", 0, 1, Int64.Type)
in
AddedIndex