Active Member
July 10, 2021
I am trying to create a column that will reset the running total to 0 or the next value in the list when the running total value hits a specific number (10000 in this case)
So it is taking in a list of numbers, adding them I need to figure out why the validation of the current sum value isnt working.
fxRunningGrouping
(values as list) as list =>
let
RT = List.Generate
(
()=> [RT = values{0}, counter = 0],
each [counter] < List.Count(values),
each if {[RT]} >= 10000 then [RT = values{[counter]}, counter = [counter]+1] else
//each if _>= 10000 then [RT = values{[counter]}, counter = [counter]+1] else
each [RT = [RT]+values{[counter]+1}, counter = [counter]+1],
each [RT]
)
in
RT
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Active Member
July 10, 2021
So I added a column that just has 10000 as the value would I be able to do something like
if [RT] >= [newColumn] then [RT = values{[counter]}, counter = [counter]+1] else ....
The idea is to reset the current total to the current value in the list. Thus resetting the total.
What happens if it doesnt reset is the addition doesnt come out right because the values can be anything.
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Hi William,
Here is an example based on:
https://www.myonlinetraininghu.....ower-query
>code>
(values as list) as list=>
let
RT = List.Generate
(
()=> [RT = values{0}, counter = 0],
each [counter] < List.Count(values),
each [RT = if [RT]>=10000 then 0 else [RT] + values{[counter] + 1}, counter = [counter] + 1],
each [RT]
)
in RT
If you don't want to reset to 0 but to the current row value (which makes more sense):
each [RT = if [RT]>=10000 then values{[counter] + 1} else [RT] + values{[counter] + 1}, counter = [counter] + 1],
Answers Post
1 Guest(s)