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 / Bug: patching/updating...
Power Apps
Answered

Bug: patching/updating last row in collection

(0) ShareShare
ReportReport
Posted on by 12

Background

I have a scenario where I have to rebuild a concatenated string. The string gets split using the Split method and I Capture the output in a single column collection. I then update the rows of the collection based on some combobox controls and have a button to Concat the table back into a string to then update the data source when complete(This method is driven by the system i'm integrating with so I need to do this string manipulation in order to update values in the source system).

 

Issue

I have found then when patching or Update a collection where the record is Last(collectionname) the behaviour isn't correct. If you are applying this logic to a single column collection where the row was originally an empty value then the patching the last(collectionname) will update the first empty row or special character rather than the last row of the collection. Even after applying a placeholder string using UpdateIf against the collection doesn't result in the behaviour changing.

 

Example:

To prove that this is not specific to data in my app, I created a blank canvas app. 3 buttons and a data table.

Picture of Example AppPicture of Example App

1.Button 1: ClearCollect the collection:

On Select code

ClearCollect(testtable,{text:""},{text:"1005"},{text:"100"},{text:""},{text:"1105"},{text:""},{text:""},{text:""},{text:""}

2. Button 2: Update Collection to fill null rows with placeholders(for my background scenario I don't need to do this but i'm just showing that it doesn't make a difference even though it should).

 

On Select code

 

UpdateIf(testtable,IsBlank(text)=true,{text:"a"})

3. Button 3: Update last row in collection

 

 

On Select code

 

Update(testtable,Last(testtable),{text:"5"})

Expected Behaviour:

 

  1. Button 1- Create collection
  2. Button 3- update Last row with value of 5
  3. last row is updated with 5

Actual Behaviour:

  1. Button 1-Create collection
  2. Button 3 - Update last row with value of 5
  3. First null value is updated with 5
    1. If you press button 3 again it will update the next null row instead of the last or the one it updated originally

First row populated with 5First row populated with 5

Same behaviour above can be replicated if you include button 2 between buttons 1 and 3. so it doesn't seem to matter if the collection has null values though somehow it knows they were null originally and the last() function no longer behaves as expected.

 

 

 

Categories:
  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Jt0 ,

    Based on the issue that you mentioned, I have made a test, and the issue is confirmed on my side.

     

    I have made a test on my side, I think this issue may be related to the placeholders string value or blank value you provided for the text column in you testtable collection.

    If the you provide a same placeholders string value (e.g. 'a') for the test column in your testtable collection, the Last() formula seems not to be able to recognize which row/record with 'a' value is the Last row.

     

    I would post this issue to my product team, if the issue is solved, I would reply here.

     

    Currently, as an alternative solution, you should provide a different placeholders string value for the test column in your testtable collection.

    I have made a test on my side, please take a try with the following workaround as alternative solution:1.JPG

     

    2.JPG

     

    3.JPG

    Set the OnSelect property of the "Init" button to following:

    ClearCollect(testtable,{text:""},{text:"1005"},{text:"100"},{text:""},{text:"1105"},{text:""},{text:""},{text:""},{text:""})

    Set the OnSelect property of the "Placeholders" button to following:

    ForAll(
    RenameColumns(testtable,"text","text1"),
    If(
    text1 = "",
    Patch(testtable,First(Filter(testtable, text = text1)),{text: "Placeholder - "&CountRows(Filter(testtable, text=text1))})
    )
    )

    Set the OnSelect property of the "LastRowUpdate" button to following:

    Patch(testtable, Last(testtable), {text: "5"})

    Please check the following GIF screenshot for more details:Test.gif

    Note: Please set a different placeholder value the test colum in your testtable collection.

     

    Best regards,

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Jt0 ,

    Just an update -- the response from @McCall Saltzman as below:

    Quick answer is that Patch affects the first record in the target table that matches the 2nd argument. In this case, First(collectiontable) is the same as Last(collectiontable). I’d suggest adding an index or some other way of uniquely identifying that record.


    The response from @Hemanth Kumar as below:

    Here as the table is a single column table and both the first and last values of the table are empty. The return of “Last(CollectionTable)” is an empty string. The call for Patch(…) will try to match the first empty string and patch that row with the provided value.  Having unique keys to identify which row you want to patch is the right way to do this in any production app. This issue is working as designed.


    On your side, please consider add a unique key/column in your table to identify which row you want to update, then try your Patch function or UpdateIf function to execute the update operation, check if the issue is solved.

     

    Best regards,

  • Jt0 Profile Picture
    12 on at

    Hey @v-xida-msft,

     

    This rational makes sense. thanks for looking into this.

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 360 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 325

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard