Skip to main content

Notifications

Community site session details

Community site session details

Session Id : MVzhG5HZg3mKuDDhURDNWT
Power Apps - Building Power Apps
Unanswered

Decrementing count in collection when collection is edited

Like (0) ShareShare
ReportReport
Posted on 28 Sep 2023 08:43:28 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!

  • MarkRahn Profile Picture
    926 Super User 2025 Season 1 on 24 Jan 2024 at 16:11:46
    Re: Decrementing count in collection when collection is edited

    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

Thomas Rice – Community Spotlight

We are honored to recognize Thomas Rice as our March 2025 Community…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,508 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,440 Most Valuable Professional

Leaderboard
Loading started