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 / Auto generate the defa...
Power Apps
Unanswered

Auto generate the default value for a field in a gallery and patch this to a collection

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a collection called 'ItemCollection' with fields like itemid, ItemLabourTime (this is the time required to manufacture an item), Labour(i.e TotalLabour, based on quantity entered) and several other fields.
I'm trying to read in the value for quantity from the user in a gallery(see screenshot below) and auto-generate the field Labour based on the value entered by the user.

ChrisEluva_0-1638389310832.png


So if a item has ItemLabourTime of 10 mins and the user enters 2 for quantity,  the labour value (i.e TotalLabour) for that item in the gallery should be 20.
I was trying to use the following formula to patch a default value for Labour to the collection -
Patch(ItemCollection, ThisItem,{Labour: ThisItem.ItemLabourTime*ThisItem.quantity})
but that was giving me an error- 'behavior function in a non behavior property'.

The plan was to set this as default and use an update in the Onchange value if the user wants to reset the auto generated value.


How can I achieve this functionality? Any help is much appreciated.

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,447 Most Valuable Professional on at

    Hi @Anonymous ,

    Try

    Patch(
     ItemCollection, 
     ThisItem,
     {Labour: Value(ItemLabourTime.Text)*ThisItem.quantity}
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Sorry, that's not working. Still giving the same error.

  • WarrenBelz Profile Picture
    154,447 Most Valuable Professional on at

    @Anonymous ,

    Where are you running the code from? To use ThisItem it must be from within the gallery. I also assume ItemLabelTime is the Text box.

  • BoHamad Profile Picture
    on at

    For labour text box in the Text property 

    use this formula Value(ThisItem.quantity)*Value(ThisItem.ItemLabourTime)

    But, to patch the values to the collection I recommend to add a button to save the data for all gallery or for a single record. Because it doesn’t make sense if u want to patch the values every time when the user change the value 

     

    hope this helps u

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WarrenBelz Yes I'm using it within the gallery.
    ItemLabelTime is not the text box, it is the predefined time required per item. The user enters the quantity and the app should generate the highlighted "Labour"(TotalLabour) field. i.e Quantity * ItemLabelTime(for that item in the gallery)
    The only reason I have the input box (text box) is to read in any changes to the automatically calculated time.

    Btw, appreciate you looking into this!

  • WarrenBelz Profile Picture
    154,447 Most Valuable Professional on at

    Hi @Anonymous ,

    If ItemLabelTime is not a control, I assume it is a field in your source data List - what type of field is it?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Yes, it is a field in my source. My source is a SharePoint list and ItemLabelTime  is of type number. 

  • WarrenBelz Profile Picture
    154,447 Most Valuable Professional on at

    @Anonymous ,

    Only one thing left then - the quantity is entered by the user?

    Patch(
     ItemCollection, 
     ThisItem,
     {Labour: ThisItem.ItemLabourTime * Value(QuantityTextBoxName.Text)}
    )

    Replace with your text box name

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Unfortunately still returning the same error! 

  • WarrenBelz Profile Picture
    154,447 Most Valuable Professional on at

    @Anonymous ,

    At this point, it is not making a lot of sense as this is the most basic of Patches referring to two items that if numeric should simply work. Put two labels in your gallery with the following

    ThisItem.ItemLabourTime

    and (whatever the text box name)

    Value(QuantityTextBoxName.Text)

    Do you see numbers in both ?

     

     

     

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!

Leaderboard > Power Apps

#1
wolenberg_ Profile Picture

wolenberg_ 119 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 107 Most Valuable Professional

#3
Haque Profile Picture

Haque 103

Last 30 days Overall leaderboard