cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lorem1960
Resolver III
Resolver III

How to save calculated result in a SharePoint column ?

I am trying to save a calculated result that is rendered in a label control to a column in SharePoint named AmountEuro

 

In my label I have the following code to calculate the allowance and this works as expected:

 

With({KM:Value(DataCardValueKm.Text),AL:First(Filter(PayrollDefaults,Title="Default")).KmAllowance},KM * AL)

 

So on my submit button the calculated result should be saved to AmountEuro, anyone has any suggestions on what the best approach would be in this scenario? Any guidance is most appreciated.

 

 

7 REPLIES 7
RandyHayes
Super User
Super User

@Lorem1960 
Consider the following change to your label formula first:

With({KM: Value(DataCardValueKm.Text), AL: LookUp(PayrollDefaults, Title="Default").KmAllowance},
    KM * AL
)

This is more efficient as it will cycle through the records of your datasource to find the first record that has Title of "Default" - then it returns it and stops.

In your existing formula, you are filtering ALL the records and then returning all the matching records, then using the First function to get the first one of the table.  So, that is much more data being transmitted and pulled into memory and then discarded.

 

As for putting it into SharePoint...are you doing this through a form?  Or do you have some other logic for where and how you are going to put the value into SharePoint?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Interesting, ok, so yes I am using a form which is in New mode, so when the user clicks on submit the result of the calculation needs to be persisted in the SharePoint column.

RandyHayes
Super User
Super User

@Lorem1960 

So then you should have the field in your form that you want the value to go into, and then in that datacard, set the DataCardValuex control Default property to: Coalesce(Parent.Default, yourLabel.Text)

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Lorem1960
Resolver III
Resolver III

Unfortunately it doesn't seem to like this I get an error

 

Lorem1960_0-1646946274816.png

 

RandyHayes
Super User
Super User

@Lorem1960 

Well you have a circular reference!  

Where is the label?  You mentioned that the formula you had was in a label - I assume that is CalcAllowance in your app.

The problem is, your label is referencing the DataCardValueAmountEuro and yet you are trying to set the default property of that same textinput.  That will not work!

 

However, I am not seeing that from your formula from before - so what is DataCardValueKM and how is that derived?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

In my label CalcAllowance is have the following:

With({KM: Value(DataCardValueKm.Text), AL: LookUp(PayrollDefaults, Title="Default").KmAllowance},
    KM * AL
)

 

And the values in DataCardValueKM are entered manually, but after given it some thought there is not really a need to store the calculated result on a column. Thanks. 

RandyHayes
Super User
Super User

@Lorem1960 

Yes, that was a consideration that I had to start with...usually visual calculations are not something that needs to be stored.

 

So, if you are not needing to store the value, then you should be good.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (3,163)