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 / Increment gallery records
Power Apps
Suggested Answer

Increment gallery records

(0) ShareShare
ReportReport
Posted on by 37
The code below works fine and increments rows from a collection connected to a gallery. I want to have it increment up until a title row and then reset to 1 on the first row after the title. The title data will be blank on the rows it needs to increment: 
 
Please modify:
 
ClearCollect(
    editTable,
    ForAll(
        Sequence(CountRows(editTable)),
        Patch(
            Last(FirstN(editTable, Value)),
            {RowNumber: Value}
        )
    )
);  
Categories:
I have the same question (0)
  • Suggested answer
    ronaldwalcott Profile Picture
    3,847 Moderator on at
    Create a new variable incrementValue set it to 1 before the ClearCollect
    You are still incrementing using Value but setting the increment to the record based on the new incrementValue variable
    You reset the incrementValue based on your condition back to 1. Not sure what you meant by after so you may have to move where you do the reset and reset to 0 instead then increment.
    The syntax is a bit off I am not typing on my desktop and I don't know exactly the condition you are checking for.
     
    Something like this should work
     
     
    UpdateContext({incrementValue: 1});
     
    ClearCollect(
        editTable,
        ForAll(
            Sequence(CountRows(editTable)),
            If(titlerowvaluecheck,UpdateContext({incrementValue: 1}));
            Patch(
                Last(FirstN(editTable, Value)),
                {RowNumber: incrementValue}
            );
            UpdateContext({incrementValue: incrementValue + 1});
        )
    );  
  • geraldc1820 Profile Picture
    37 on at
    Thank you. That concept makes sense but PowerApps will not allow variables set inside a ForALL.
  • ronaldwalcott Profile Picture
    3,847 Moderator on at
    Didn't realise that.
     
    Instead of using a variable we can try using a table with patch.
     
    Set(incrementTable, Table({valueIncrement:1}));
     
    Patch(incrementTable, First(incrementTable), { valueIncrement:First(incrementTable).valueIncrement + 1 })
     
    Replace as appropriate and see if it works. I am assuming that Patch does not execute concurrently and ForAll waits for the completion.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 93 Most Valuable Professional

#2
Haque Profile Picture

Haque 81

#3
Valantis Profile Picture

Valantis 49

Last 30 days Overall leaderboard