web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Running total in a col...
Power Apps
Answered

Running total in a collection/sharepoint list or How to create a fibonacci sequence inside of a ForAll Loop

(0) ShareShare
ReportReport
Posted on by 8

I have a need to create a running total inside of a ForAll loop.  Basically a Fibonacci sequence of adding the previous running total to the current record in a collection/sharepoint list.  Before I start, let me state that I realize I can hard code this, but I am attempting to find a solution to allow for a dynamic number of steps. 

 

I have a business process that is built on 18 steps.  As part of creating the project, the end user edits the SLA for each stage.  What the app needs to do next is calculate the due date of each stage, taking into account the number of days used before it.  I have all the code worked out for calculating business days/holidays for up to 3 years, but where I am struggling is getting the actual date for each subsequent stage because it doesn't know how many running days to add or what the previous date was.  (This is where I know I could create 18 text boxes and assign each a value and do a running total.  However I'm trying not to hard code it to allow for when there are more/less stages in the process in the future).  

 

As I said, getting the actual date is not the problem, it's knowing how many days to add.  Any thoughts or suggestions would be much appreciated.

 

  Column I need to calculate 
 DaysTotal Days Actual Date
Start11 
Stage 212 
Stage 335 
Stage 416 
Stage 5713 
Stage 6316 
Stage 7521 
Stage 8122 
Stage 91032 
Stage 10436 
Stage 11339 
Stage 12342 
Stage 13244 
Stage 14549 
Stage 15352 
Stage 16153 
Stage 17356 
Finish561 

 

stages.png
Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 Moderator on at

    @sbedows 
    Bring your SharePoint list into a collection.  I have filtered the list based on a project number

    ClearCollect(colData, Filter(your_SP_list, ProjectID=1));

     

    Place your collection inside a gallery.

    colData

     

    Then insert a label and use this code in the Text property of the gallery. 

    Sum(Filter(colData, ID<=ThisItem.ID), Days)

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • sbedows Profile Picture
    8 on at

    @mdevaney - Thank you.  If I want to collect it back to the same collection (or a new collection), can I use that formula inside a ForAll or some way to create that column in the collection?

  • Verified answer
    mdevaney Profile Picture
    29,991 Moderator on at

    @sbedows 

    Here's how to do it.  Assume we have collection that looks like this

     

    ClearCollect(colData,
     {ProjectID: 1, StageID: 1, StageDays: 1},
     {ProjectID: 1, StageID: 2, StageDays: 2},
     {ProjectID: 1, StageID: 3, StageDays: 6},
     {ProjectID: 1, StageID: 4, StageDays: 4},
     {ProjectID: 2, StageID: 1, StageDays: 3},
     {ProjectID: 2, StageID: 2, StageDays: 5}
    );

     

     

    Then you can use this code to create a new collection for Project #1 with the RunningTotal included.

     

    ClearCollect(
     colSolution,
     AddColumns(
     Filter(colData, ProjectID=1) As TableXY,
     "RunningTotal",
     Sum(Filter(colData, StageID<=TableXY.StageID), StageDays)
     )
    );

     

     

    The final result will look like this:

     

    ProjectID StageID StageDays RunningTotal
    1 1 1 1
    1 2 2 3
    1 3 6 9
    1 4 4 13

     

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • Thrive Profile Picture
    34 on at

    What if you have more than one project ID?  Can this be done without hardcoding the Project ID into the filter function?

     

    Filter(colData, ProjectID=1) As TableXY,

     

  • sbedows Profile Picture
    8 on at

    @Thrive  - Yes, you can do this in a ForAll loop.  Using the same collection as @mdevaney above, the code would look like...

     

    Clear(colSolution);
    ForAll(Distinct(colData,ProjectID),
    Collect(
     colSolution,
     AddColumns(
     Filter(colData, ProjectID=Result) As TableXY,
     "RunningTotal",
     Sum(Filter(colData, StageID<=TableXY.StageID, ProjectID=Result), StageDays)
     )
    ));

     

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 377 Most Valuable Professional

#2
11manish Profile Picture

11manish 165 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 110 Super User 2026 Season 2

Last 30 days Overall leaderboard