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 / re-sort existing recor...
Power Apps
Unanswered

re-sort existing records after a record deletion; if record is NOT last, re-sort remaining records in collection/gallery

(0) ShareShare
ReportReport
Posted on by 127

Hello All,

I bet 50% of posts are help me, I've spent "X" hours on this, I'm desperate...

"Please, I need help, I've spent almost 2 weeks on this. I'm desperate!!

 

Have a Contact directory app. User filters contacts based on City, then can view/Edit an existing contact. They can also add a new contact to the city. Deleting is the part where I'm stuck. If they delete a record, the other ones need to move up one (a.k.a. be promoted in priority). I either get circular error, or "incompatible comparison" errors (ex: cannot compare a record to text).

 

Objective: If the "varSelectedRecord" is equal to the last record in the gallery,  Remove "varSelectedRecord", else Remove"varSelectedRecord" AND re-order the "Priority", a number stored as text(1,2,3...), for the remaining records in the gallery.

 

If(Last(GalleryT)) = varSelectedT.selected, Remove(GalleryT, Last(GalleryT)), Remove(varSelectedT, varSelectedT.Selected) && ForAll(GalleryT, Sum(gallery.priority - 1))

 

I also tried using this with a collection called, "colT", but I ended up in the same place, here 🙂

 

I was building this formula into a Button control in the "OnSelect" property. I created a pop-up, so when the user confirms "delete" this IF statement would be executed.

 

The data in coming from a SharePoint, so if this is not possible, then I'm open to other suggestions. Hopefully, I'll be able to use Dataverse, soon. I started out with a Choice field in the form and was trying to filter out "Priority" that were existing, but the choice field could not be evaluated in everything I've tried.  I still very much consider myself a newbie at all of this. There are not a lot of records, only 3 contacts per city, so delegation is not an issue I can see.

 

Thank you, again!

Categories:
  • KiranKhanvilkar Profile Picture
    26 on at

    Hi @Dianez , 

     

    Try using the below if statement. I am using colProjectsFinalRank as primary collection and coltemp as temporary collection. We need to use temp collection as we cannot just loop through the same data and simultaneously update it also. Also, in If statement you can include multiple steps separating it by ":" semicolon.

     

    If(
    Last(colProjectsFinalRank).ID = ThisItem.ID,
    Remove(
    colProjectsFinalRank,
    Last(colProjectsFinalRank)
    ),
    Remove(
    colProjectsFinalRank,
    ThisItem
    );
    ClearCollect(
    colTemp,
    RenameColumns(
    colProjectsFinalRank,
    "ID",
    "NewID"
    )
    );
    ForAll(
    colTemp,
    UpdateIf(
    colProjectsFinalRank,
    ID = NewID,
    {Priority: ThisRecord.Priority - 1}
    )
    )
    )

     

    ---
    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.

  • Dianez Profile Picture
    127 on at

    Thank you for your reply. I'll try it out as soon as I can. I goofed on the message, too. 

    It needs to re-sort all the remaining records in the collection because if the record to be deleted is 2, then moving the other ones up will create a record with "0" and one with "2" and they are not sequential. Thanks!

  • Dianez Profile Picture
    127 on at

    @KiranKhanvilkar 

     

    I got it to work with the help of PowerApps 911. The gallery to make the collection and the form need to be on the same screen. I had them on different screens. Then it's a really long formula that patches a sequence of indexed records through a ForAll loop. Don't know if that makes sense, but it worked.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard