
Hello, I am fairly new to power apps and mocking up an app to gather a variety of data to upload to a SQL server.
I have got a gallery with multiple job roles, their salary and then the % of areas they work in.
In the database 1 = 100% so I have used this formula.
Text((ThisItem.StaffPercHost*100),"[$-en-US]0%")
I want users to be able to edit the data and the % spread of each role, however, I do not want them to give a role a % spread not equaling 100%.
After editing the data, there is a save icon using the below formula
Select(Parent);
Patch(
'[dbo].[fp_tco_stafftable]',
{StaffID: ThisItem.StaffID},
{
StaffRoleName: txtStaffRoleName.Text,
StaffSalary: Value(txtStaffSalary.Text),
StaffPercHost: Value(txtStaffPercHost.Text)
}
);
Set(
itemId2,
0
)
I would like an error to appear when attempting to submit IF the total % spread is not exactly 100%. It would also be nice to have a total % column so the user can see how much they are over or under... or even better yet, a count down column to say how much % is left to be distributed for that row. I'll add a screenshot to try better explain. Thank you in advance!
You can utilize the Sum function for what you are trying to achieve.
In your case you will use the Gallery.AllItems as the source to Sum.
So, if it is the txtStaffPercHost control that has that value, then consider this formula for a sum:
Sum(yourGallery.AllItems, Value(txtStaffPercHost.Text))
You can then use that perhaps in a label (outside of your gallery) to display the sum and perhaps with some more math, the remaining.
You could then use that to control the visibility of an error label.
SO...let's say you put the Sum formula above in the Text property in a label outside your Gallery called lblPercentSum.
Then, you could put another label (let's call it lblSumError) outside the Gallery that would have the "error" text in it and set the Visible property to the following:
Value(lblPercentSum.Text) <> 100
This would display if the value is not equal to 100.
Then, for your "Save" icon, set the DisplayMode property to the following:
If(lblSumError.Visible, Disabled, Edit)
That would disable save/submit if they have incorrect sum of percentages.
I hope this is clear and helpful for you.