cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Muhja
Advocate I
Advocate I

Adding All Records Numbers to Check if they amount to 100%

Hi there experts,

 

Would like a little help please. the scenario goes, that I have a sharepoint list called 'Entries', one column has the values of percentages. I want the user to be able to enter items (5-6) each with percentages and when the percentage total reaches 100, to show message and prevent further entries. Further more I want to restrict entries of (5-6) record for each user in a specific year, if he/she tries to enter next year app will allow it.

 

I have a 'Save button' to submit entries of a form, I want to add the check (where i read all lines in list within this year and under the same user name, then if the percentage not reached 100, to allow it). Something like the below code (with the right syntax ;))

 

If(User().FullName in Entries.Created_By,

 Entries.Percentage (Get all records with the same user in this year) => when 100% reached show error, otherwise allow entry with notification on how much percentage remains to complete 100%. like below (25%+30%+40%) = 95% .

 

8fdf5646-73b0-4874-8958-5bd037e33416.jpg

Can someone help me please, much appreciated.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-JessicaG-msft
Community Support
Community Support

Hi @Muhja ,

 

According to your description I did a simple test, I filter all the values in the current user percentage column to determine whether the sum of the values reaches 100%.  If the value is greater than 1, an error message is displayed; if it is less than or equal to 1, the form record can be submitted and the remaining percentage is displayed.

 

Please refer to the formula in the screenshot:

vJessicaGmsft_0-1638874487615.png

vJessicaGmsft_2-1638876600274.png

 

If(
    Sum(Filter(Entries,(Created >= Date(Text(varyear),1,1))&&('Created By'.Email = name)),percentages) + percentages_DataCard2.Update > 1, 

    Notify("Percentage reaches 100", NotificationType.Error),

    SubmitForm(Form2);Notify( 1-Sum(Entries,percentages) & " remains to complete 100% " )
    
    )

 

Best Regards,

Jessica Gu

View solution in original post

Muhja
Advocate I
Advocate I

Thank you Jessica,

 

That was quite helpful, I have used your approach and tweaked it a bit to fit my requirements. Here is how I did it for others to benefit from.

 

1- In the form I have created a drop down box an populated the percentages values needed, e.g. in the dropdown box Item controls:

["5%", "10%", "15%", "20%", etc.]

 

2- Created a label field, and in Text control added the following calculation to sum the entered values the user keeps saving every time he/she makes an entry and then clicks 'Save' (which is practically SubmitForm command with condition), code: Sum(Filter(DataSourceName,UserEmail=varUserEmail),PercentageValue).

 

3- Add another label field to show message resulting based on the sum value of the percentages. Concatenated some stuff to make the message presentable, Code:

If(Sum(Filter(DataSourceName,UserEmail=varUserEmail),PercentageValue)=1,Blank(),Concatenate("* Please check your entries, total of percentages not equal to 100%. Currently total is: ", (Sum(Filter(DataSourceName,UserEmail=varUserEmail),PercentageValue)*100),"%")).

 

4- on Submit button, add the check where the value of the label compared to 1. Code sample:

If (Value(Label1.Text) < 1 || Value(Label1.Text) > 1,
UpdateContext({ShowMessage: Notify("Please check percentages total must be exactly 100%", NotificationType.Error)}),
ForAll(RenameColumns(DataSourceName, "ID", "ID1"), Patch(DataSourceName, LookUp(DataSourceName, ID = ID1 && UserEmail = varUserEmail ), {Status: "Pending for Approval"})));

 

Hope this is helpful, appreciate the support.

View solution in original post

2 REPLIES 2
v-JessicaG-msft
Community Support
Community Support

Hi @Muhja ,

 

According to your description I did a simple test, I filter all the values in the current user percentage column to determine whether the sum of the values reaches 100%.  If the value is greater than 1, an error message is displayed; if it is less than or equal to 1, the form record can be submitted and the remaining percentage is displayed.

 

Please refer to the formula in the screenshot:

vJessicaGmsft_0-1638874487615.png

vJessicaGmsft_2-1638876600274.png

 

If(
    Sum(Filter(Entries,(Created >= Date(Text(varyear),1,1))&&('Created By'.Email = name)),percentages) + percentages_DataCard2.Update > 1, 

    Notify("Percentage reaches 100", NotificationType.Error),

    SubmitForm(Form2);Notify( 1-Sum(Entries,percentages) & " remains to complete 100% " )
    
    )

 

Best Regards,

Jessica Gu

Muhja
Advocate I
Advocate I

Thank you Jessica,

 

That was quite helpful, I have used your approach and tweaked it a bit to fit my requirements. Here is how I did it for others to benefit from.

 

1- In the form I have created a drop down box an populated the percentages values needed, e.g. in the dropdown box Item controls:

["5%", "10%", "15%", "20%", etc.]

 

2- Created a label field, and in Text control added the following calculation to sum the entered values the user keeps saving every time he/she makes an entry and then clicks 'Save' (which is practically SubmitForm command with condition), code: Sum(Filter(DataSourceName,UserEmail=varUserEmail),PercentageValue).

 

3- Add another label field to show message resulting based on the sum value of the percentages. Concatenated some stuff to make the message presentable, Code:

If(Sum(Filter(DataSourceName,UserEmail=varUserEmail),PercentageValue)=1,Blank(),Concatenate("* Please check your entries, total of percentages not equal to 100%. Currently total is: ", (Sum(Filter(DataSourceName,UserEmail=varUserEmail),PercentageValue)*100),"%")).

 

4- on Submit button, add the check where the value of the label compared to 1. Code sample:

If (Value(Label1.Text) < 1 || Value(Label1.Text) > 1,
UpdateContext({ShowMessage: Notify("Please check percentages total must be exactly 100%", NotificationType.Error)}),
ForAll(RenameColumns(DataSourceName, "ID", "ID1"), Patch(DataSourceName, LookUp(DataSourceName, ID = ID1 && UserEmail = varUserEmail ), {Status: "Pending for Approval"})));

 

Hope this is helpful, appreciate the support.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,831)