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 / ForAll patch column on...
Power Apps
Answered

ForAll patch column only last record - incorrectly

(0) ShareShare
ReportReport
Posted on by 521

Hi,

I am trying to create a record using Patch ForAll works fine exempt one column which I need to use a text input inside the gallery  so it will record the any amount entered each of the text input, currently what it does it records last entered amount for all the rows and I  will be needing your assistance Thanks 

PPayment.PNG   

Patch(
 PPayments,
 ForAll(
 Filter(
 ColPProject,
 tglPPayment.Value
 ) As aCol,
 { 
 Title: Now(),
 'Payment Amount':Value(txtPPaymentControl.Text),
 
 
 RecordID:aCol.ID
 
 }
 )
)




Categories:
I have the same question (0)
  • Shaheer Ahmad Profile Picture
    2,194 Moderator on at

    To fix the issue where only the last entered amount is being recorded for all the rows in your Patch formula using ForAll, you need to modify your formula slightly. Currently, you are referencing a single text input control (txtPPaymentControl.Text) for all the records. To capture different amounts for each row, you need to access the corresponding text input control within the ForAll loop. Here's an updated version of your formula:

     

    Patch(
     PPayments,
     ForAll(
     Filter(
     ColPProject,
     tglPPayment.Value
     ) As aCol,
     { 
     Title: Now(),
     'Payment Amount': Value(Gallery1.Selected.txtPPaymentControl.Text),
     RecordID: aCol.ID
     }
     )
    )

     

    In the above formula, Gallery1 is the name of your gallery control where you have the text input controls. Replace Gallery1 with the actual name of your gallery control. I assumed that you want to use the text input control of the selected record in the gallery to capture the payment amount. If you have multiple text input controls in each row of the gallery, make sure to modify txtPPaymentControl to reference the correct text input control for the corresponding row.

    By using Gallery1.Selected, you can access the selected record in the gallery, and then txtPPaymentControl.Text will retrieve the payment amount from the text input control of that specific row.

    With this change, each record in the ForAll loop will capture the corresponding payment amount from the text input control, rather than using the last entered amount for all rows.

  • PowerApps11 Profile Picture
    521 on at

    Hi @ShaheerAhmad 
    I have tested still same it will only record first entered amount for all rows

  • Uditha_ISH Profile Picture
    45 on at

    Try this method,

     

     

    ForAll(
     Filter(
     ColPProject,
     tglPPayment.Value
     ) As aCol,
     Patch(
     PPayments,Defaults(PPayments),
     { 
     Title: Now(),
     'Payment Amount':Value(txtPPaymentControl.Text),
     RecordID:aCol.ID
     }
     )
    )

     

  • Shaheer Ahmad Profile Picture
    2,194 Moderator on at

    Apologies for the confusion. In that case, you can try using a variable to store the current payment amount within the ForAll loop. Here's an updated version of the formula:

     

    Patch(
     PPayments,
     ForAll(
     Filter(
     ColPProject,
     tglPPayment.Value
     ) As aCol,
     {
     Title: Now(),
     'Payment Amount': Value(txtPPaymentControl.Text),
     RecordID: aCol.ID
     },
     {
     // Initialize a variable to store the current payment amount
     paymentAmount: Value(txtPPaymentControl.Text)
     }
     )
    )

     

     

    In this formula, we added a new line within the ForAll loop that initializes a variable called paymentAmount with the value from txtPPaymentControl.Text.

    Then, when assigning the 'Payment Amount' field in the Patch function, you can use this variable instead of directly referencing txtPPaymentControl.Text. Here's the updated line:

     

     

    'Payment Amount': paymentAmount

     

     

    With this change, each record in the ForAll loop will use the payment amount stored in the paymentAmount variable, ensuring that each row has the correct value.

    Please give this updated formula a try and let me know if you're still experiencing any issues.

  • Shaheer Ahmad Profile Picture
    2,194 Moderator on at

    The formula you provided will create a separate Patch function call for each record in the ForAll loop. While this approach will work, it may result in multiple calls to the data source, which can impact performance if you have a large number of records.

    Alternatively, you can modify the formula to use a single Patch function call outside the ForAll loop. Here's an updated version:

    Patch(
     PPayments,
     ForAll(
     Filter(
     ColPProject,
     tglPPayment.Value
     ) As aCol,
     {
     Title: Now(),
     'Payment Amount': Value(txtPPaymentControl.Text),
     RecordID: aCol.ID
     }
     )
    )

    In this formula, the Patch function is called once, and the ForAll loop is used to generate a table of records to be patched. Each record in the ForAll loop captures the desired fields, including the payment amount from the text input control.

    By using a single Patch function call, you can potentially optimize performance, especially when dealing with a large number of records.

    Give this updated formula a try and see if it resolves the issue you were facing.

  • Verified answer
    PowerApps11 Profile Picture
    521 on at

    @ShaheerAhmad 
    Sorry did not worked, I end up creating a column to record then fetch. 

    Thanks 

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

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 342 Most Valuable Professional

#2
11manish Profile Picture

11manish 234

#3
Valantis Profile Picture

Valantis 187

Last 30 days Overall leaderboard