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

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Decrementing count in ...
Power Apps
Unanswered

Decrementing count in collection when collection is edited

(0) ShareShare
ReportReport
Posted on by 205

Hi all,

 

I have created a gallery which uses a collection as its data source, this collection is generated when the screen becomes visible as such - ClearCollect(Findings, {no:1}). I also have a button that creates additional rows in the collection - Patch(auditFindings, Defaults(Findings), {no:CountRows(Findings)+1). In the gallery, I have a field called reportnumber-00X whereby X is thisitem.no

 

The problem comes in when I try to delete the entry in the gallery (done through a button in the gallery with onSelect property of RemoveIf(Findings, no=thisitem.no) . I would like the field reportnumber-00X to update automatically. E.g. if i have reportnumber-001, reportnumber-002, reportnumber-003, reportnumber-004 and I delete reportnumber-002, the gallery should show reportnumber-001, reportnumber-002, reportnumber-003 instead of reportnumber-001, reportnumber-003, reportnumber-004. How can this be achieved? TIA!

Categories:
I have the same question (0)
  • MarkRahn Profile Picture
    1,330 Super User 2026 Season 1 on at

    Hi @ccqn ,

     

    I have had to do something similar. This is how I achieved what you are trying to do:

    1) In the OnVisible of a Screen, use:

     

    ClearCollect(Findings, {no:1,Title:"Item1"})

     

    2) Add a Gallery to the Screen and a "+" icon above it:

    MarkBandR_0-1706112199515.png

    3) Set the Gallery Data Source to "Findings". Add two Labels to the Template for the Gallery and link them to the "no" value and the "Title" value.

    4) For the "+" icon, set the OnSelect to:

     

    Collect(Findings, {no:CountRows(Findings)+1, Title:"Item" & Text(CountRows(Findings)+1)})

     

    5) In the Template for the Gallery, add a "Trash"can icon. Set the OnSelect to:

     

    RemoveIf(
     Findings,
     no = ThisItem.no
    );
    ClearCollect(
     Findings,
     With(
     {records: Findings},
     ForAll(
     Sequence(CountRows(records)),
     Patch(
     Last(
     FirstN(
     records,
     Value
     )
     ),
     {no: Value}
     )
     )
     )
    );

     

     

    With the example, you should now be able to add and delete items. The "no" field will update. See below:

    MarkBandR_1-1706112608578.png

    The item with the Title "Item3" was deleted and the other items renumbered.

     

    I pulled this example together using this article:

    https://powerapps.co.nz/auckland/index.php/our-blog/41-add-alternating-row-colours-to-power-apps-gallery

     

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up.

    Thanks.

    -Mark

     

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 254 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 211 Super User 2026 Season 1

#3
VASANTH KUMAR BALMADI Profile Picture

VASANTH KUMAR BALMADI 195

Last 30 days Overall leaderboard