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 / Create a Calculated Co...
Power Apps
Answered

Create a Calculated Column in a Collection from Sharepoint List Data

(0) ShareShare
ReportReport
Posted on by 57

Hello everyone,

 

This is my first post so I apologize in advance if it's in the wrong place or format.

 

Here is my problem. I have created an app to use for inventory purposes. The basic premise of my app is that users will select which location they are completing the inventory for, conduct an on hand inventory, generate a report that calculates inventory required based on min-max data, and then submit.

 

To this point everything has gone well, I have been able to pull the sharepoint data into a collection, display it properly in the gallery, have + - buttons in the gallery that patch the adjusted current inventory values back to the collection, and navigate to the submit screen which filters the collection to only show the data which requires ordering (ie anything which is >0 and < min order shows up, everything else just shows a 0).

 

Now the problem. I originally had a Sharepoint column that would calculate (Max Stock - Current Stock, in an IF statement to ensure it only applies if the current stock was lower than the min stock and above zero). The problem was that I couldn't patch the collection back to the Sharepoint list because the calculated column wouldn't accept an update (makes sense to me, the column is calculated and therefore read-only). I changed the sharepoint column back to a number column and have been attempting some version of a calculated column in a collection but am at a total loss as I cannot seem to write the IF statement into the PATCH properly.

 

My data source is station4, my collection name is colorder, and the if statement is as follows,

 

If(
And(
Max_x002e_Stock-CurrentStock>0,
CurrentStock<Min_x002e_Stock
),
Max_x002e_Stock-CurrentStock,
0
).

 

This all works if I ClearCollect it into another collection (colmath) using AddColumn (Picture added below) , but then the column names don't match and I still can't patch to update the station4 datasource.

 

Any suggestions would be greatly appreciated!

 

Thanks,

Shawn

Screen Shot 2022-01-09 at 10.21.24 AM.png
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    156,277 Most Valuable Professional on at

    Hi @ShawnSchinkel ,

    A few things - you do not need the second argument as if current stock is less than Maximum Stock, the result will be less than zero.

    ClearCollect(
     colmath,
     AddColumns(
     colorder,
     "Order Quantity",
     If(
     Max_x002e_Stock - CurrentStock > 0
     Max_x002e_Stock - CurrentStock, 
     0
     )
     )
    );
    Navigate(
     ReorderScreenl,
     Cover
    )
     

    Next I assume you have the ID of the relevant records in station4 in your collection to identify the records to be patched ? Lastly, what is the name of the field in station4 that you need to Patch 'Order Quantity' to?

     

  • ShawnSchinkel Profile Picture
    57 on at

    Hi @WarrenBelz and thanks for the quick reply!

     

    Just to explain my thinking on the second argument, I wanted the stock to only order if the current quantity was less than the Min stock allowed on hand but more than 0. The issue I had when I first set it up was that if we by chance had more inventory on hand than the max value, Max - Current would result in a negative number then adding even more to the Order Quantity. Ex. Max Stock of 10, Min Stock of 5, Current Stock of 12 would result in -2 with the calculation, and then the code would order up to the Max resulting in another 12 items being ordered when in reality it should be 0.

    To answer your second question, I used ClearCollect(colorder,station4) to create the colorder collection from the station4 Sharepoint list and colorder to make colmath so I believe the ID numbers should all match. The column in station4 is named Order Quantity in Sharepoint so with the exception of the space the names should be the same.

     

  • Verified answer
    WarrenBelz Profile Picture
    156,277 Most Valuable Professional on at

    Hi @ShawnSchinkel ,

    I assume both names have spaces ? Whatever the case, they need to be the same in the collection and the list. Try the below for the Patch

    With(
     {
     wPatch:
     ShowColumns(
     colmath,
     "ID"
     "Order Quantity"
     )
     },
     Patch(
     station4,
     wPatch
     )
    )

     

    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

  • ShawnSchinkel Profile Picture
    57 on at

    Good Morning @WarrenBelz ,

     

    That formula did work, with exception of a small typo (3rd line - wPatch) which I was able to figure out. My final solution to create the calculated column is as follows:

    Datasource = STATION_4

    Collection= colorder (complete copy of STATION_ 4 so I have all the data columns for other item information)

    Collection= colmath (from colorder but only with Columns ID, Description, MaxOrder, MinOrder, CurrentStock)

    Collection=colcalc (from colmath, but used AddColumn to add OrderQuantity with the IF statement for the calculation)

     

    Using your With formula I was able to patch the OrderQuantity from colcalc back to STATION_4 and then call it for the next screen.

     

    I could probably simplify by completely removing the colmath collection and instead just manually enter all of the columns required minus OrderQuantity when creating the colorder collection.

     

    Thanks again!

    Shawn

  • WarrenBelz Profile Picture
    156,277 Most Valuable Professional on at

    Thanks @ShawnSchinkel ,

    Not sure where the typo was (that is a standard With() statement syntax - you can use whatever name you want)

  • ShawnSchinkel Profile Picture
    57 on at

    Gotcha, my misunderstanding, I thought the wPatch: was supposed to only be Patch.

     

    Shawn

  • WarrenBelz Profile Picture
    156,277 Most Valuable Professional on at

    @ShawnSchinkel ,
    Actually typo was at the bottom - now fixed.

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 396 Most Valuable Professional

#2
11manish Profile Picture

11manish 134 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 101 Super User 2026 Season 2

Last 30 days Overall leaderboard