Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Query
Unanswered

Help with a reset running total on two criteria

(0) ShareShare
ReportReport
Posted on by 6

Hello,

New poster so go gentle with me!

 

My issue is fairly straight forward but I just don't seem to be able to solve it.

 

I have 3 columns of data:-

POSplitRows - This is a grouping of data lines based on other criteria not relevant to this issue.

Units - Values attributable to each "POSplitRows" line

Running Total - Running total of "Units" that I would like to reset when two criteria are reached 1. Reset when the "POSplitRows" grouping changes and 2. Reset within each "POSplitRows" grouping if the running total exceeds or equals 5000.

 

My solution

 

1. Extracted the columns needed from source data

2. Buffered "Units" & "POSplitRows" as lists

3. Created a custom function with the code below:-

 

= (values as list) as list =>
let
GRTList = List.Generate(
()=> [ GRT = values{0}, i = 0 ],
each [i] < List.Count(values),
each try
if [GRT] + values{[i]} <= 5000
then [GRT = [GRT] + values{[i] + 1}, i = [i] + 1]
else [GRT = values{[i] + 1}, i = [i] + 1]
otherwise [i = [i] + 1] ,
each [GRT] )
in
GRTList

 

4. Applied this function code to the data at stage 2 using the custom code below:-

 

= Table.FromColumns(
{
Source[POSplitRows], Source[Units],
fxRunningUnitGroupx(BufferedUnits, BufferedIndex)
},
{
"POSplitRows",
"Units",
"Running Total"
})

 

Problem

 

The split to reset at 5000 units seems to be working as expected (Yellow box below) but the reset based on the "POSplitRows" grouping is performed on the second line of the new "POSplitRows" grouping (Red Box below). I want the "Running Total" column to show the first line of the new grouping as the new running total (ie Start at 404 units, not 287)

 

cjdj2005_0-1705317156644.png

I think it is something not quite right in my fuction coding above. If anyone can offer any ideas I would be grateful.

 

Thanks.

 

  • cjdj2005 Profile Picture
    6 on at
    Re: Help with a reset running total on two criteria

    Hi, many thanks for this.

    My source is a query rather than an excel file. I have remapped the source to the Query within Power Query.

     

    It is taking a long time to run. Do I need to remap any other elements of the code to the discrete query name of my source within the function part of the coding?

  • cjdj2005 Profile Picture
    6 on at
    Re: Help with a reset running total on two criteria

    Many thanks.

     

    I attempted some code in a function in my original post. It really is just offsetting the POSplitRows by one line as described above. It may just be something I have missed in that code above.

  • cjdj2005 Profile Picture
    6 on at
    Re: Help with a reset running total on two criteria

    Many thnaks for this.

     

    I forgot to mention I am using the Power Query engine behind Excel and not Power BI.

     

    Can I enter the DAX code or can it be adapted for Power Query for Excel?

     

    Thanks again

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Query

#1
mmbr1606 Profile Picture

mmbr1606 9 Super User 2025 Season 1

#2
SD-13050734-0 Profile Picture

SD-13050734-0 6

#3
stampcoin Profile Picture

stampcoin 2

Overall leaderboard

Featured topics