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 / Why would UpdateIf add...
Power Apps
Unanswered

Why would UpdateIf add a new blank record to a collection sometimes?

(0) ShareShare
ReportReport
Posted on by 22

I have a collection of records, and a collection of selected records from that first collection.

My intent is to have a form that will update all the selected records in the first collection with the values from the form, depending on if a value was entered into the form or not.

 

This works with textboxes but when I try to update one of the fields (a multi-select choice field, so a table of "Value") I get two different problems:

  • Around 1 in every 5 times it will instead create a new blank record in the collection holding only that one multiple choice field
  • Another 1/5 chance of nothing happening at all

 

The code that works 3/5 times and breaks in two different ways is something like this:

 

With({ newItems: cmbNewAddItem.SelectedItems },
 UpdateIf(colPurchaseItems, Index in colSelections.Index, {
 Quantity: Coalesce(Value(txtNewEditQuantity.Text), Quantity),
 ActualPrice: Coalesce(Value(txtNewEditPrice.Text), ActualPrice),
 GL: Coalesce(Value(txtNewEditGL.Text), GL),
 Items: If(CountRows(newItems) > 0,
 newItems,
 Items
 )
 })
)

 

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sfasweqq 

    Your problem is that you have a syntax issue with the UpdateIf.

    The second parameter of the UpdateIf is the criteria that is used to match a record.

    Your criteria is Index in colSelections.Index.  So this will evaluate to true if the Index is in that collection and false if not.  That will NOT match the record.  

    You need to specific actual criteria for that record.

    I am not able to provide too much more information as these see to be some made up collections that have a variety of purposes. 

    If the above doesn't give you a clue as to what to change, then if you can expand on the purposes and meanings of the Index and the other collection perhaps that would assist.

     

    I hope this is helpful for you.

  • sfasweqq Profile Picture
    22 on at

    Hi, I'm a little confused.

    Doesn't

    colPurchaseItems, Index in colSelections.Index

     match true if the item in colPurchaseItems has an Index column that is in colSelections.Index, so it will only update those items?

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sfasweqq 

    Yes and no - 

    Yes it will be true if Index is in colSelections.Index.

    No it will not necessarily just update those items.  However, they would if Index is as column in the collection - but, it's only going to do it once.  

     

    AND, looking at it from the perspective of Index and an Index collection, then I would say you are better off working from that collection as the source rather than the other.

     

    My other question would be - is Index the primary key of the data?  Or, is this in a SharePoint list datasource that you are originating from?

  • sfasweqq Profile Picture
    22 on at

    Thanks for helping, it actually ended up being a dumb mistake on my part and nothing to do with the code I shared. I had another combo box with a Default and OnChange update that was firing after that code and either cancelling the change or inserting blank rows based on how fast things happened I guess.

     

    Sorry for wasting your time!

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sfasweqq 

    No problem!  Always good to avoid On... actions that perform actual logic like that.  They will bite you in the end and it's not really the "PowerApps way".

     

    Glad you found it!!

  • 55552 Profile Picture
    676 on at

    I am having the exact same issue. I have a button that uploads data from a Collection to a Dataverse data table using UpdateIf.  I loop through all the records in the Collection using ForAll. Occasionally, even when there is a single record in the Collection, instead of updating my matching value from the Dataverse table, it adds 2 new blank records instead.  Code is here: 
    //Loops through the collection and then updates Dataverse table only with items/rows in the collection, clears collection
    ForAll(
    PieceAddInfo,
    UpdateIf(
    TaraconYards,
    PieceUID = PieceUID_Col,
    {
    Location: Location_Col,
    PieceStatus: PieceStatus_Col,
    PieceNote: PieceNote_Col,
    TrailerNumber: TrailerNumber_Col

    }
    )
    );
    Clear(PieceAddInfo)

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 541

#2
WarrenBelz Profile Picture

WarrenBelz 434 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 289

Last 30 days Overall leaderboard