cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JFexp
Regular Visitor

A check before submitting that ensures the sum of entries in a form is equal to a number

I have a form that is taking a data from Monday to Sunday from a choice of 0, 4, or 8.

 

When a user clicks submit I would like that to check if the data entered Monday to Sunday is equal to 40.

 

If the hours being submitted is greater or less that 40 a message will appear to inform the user that it has not been accepted and they are returned to the form to update the form again.

 

Extra: I'm also trying to have a running total hours that is displayed and updated as the user selects 0, 4 or 8 in the fields. e.g. if 8 is selected for monday and 8 for Tuesday the total will update to 16.

1 ACCEPTED SOLUTION

Accepted Solutions

@JFexp 

The formula will be a bit lengthy because you have individual columns for each daily entry, but the general idea is this -

1) Put a Label control on the screen - some where you like and outside of the EditForm.  Name the Label control - lblHourSum

2) Determine the DataCardValue control for each of your DataCards.  I'm going to make a couple of guesses here based on what I believe you have for each one (i.e. these are ComboBox controls).  

So, in the datacard for Monday_Activity_1 (if you expand that datacard) you should see several controls in it.  One of them will be DataCardValuex - where x is a number.  Determine all of the DataCardValue controls in each one and then construct a formula for your lblHourSum Text property as follows (I am using sequential numbers here for each control, so replace them with the names of the controls that you determined above) :

Value(DataCardValue1.Selected.Value) + 
Value(DataCardValue2.Selected.Value) + 
Value(DataCardValue3.Selected.Value) + 
Value(DataCardValue4.Selected.Value) +
<… and so on for all the controls for Monday through Sunday …>

3) Add a Label control to the screen.  Somewhere you like outside of the EditForm.  Name the Label control lblNotice.  Set the Text property to : "Please adjust your hours, must total 40."  (or whatever you want it to say).  Set the Visible property to : !(Value(lblHourSum.Text)=40)

 

4) Set the DisplayMode of the IconAccept1 to : If(lblNotice.Visible, Disabled, Edit)

This will disable your submit icon/button if the notice about the hours is displayed (hours not 40).

 

This should give you what you are looking for.

See if that helps or if you have other questions.

 

 

 

_____________________________________________________________________________________
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!

View solution in original post

3 REPLIES 3
RandyHayes
Super User
Super User

@JFexp 

Can you share a little more about your scenario?  Is this all in an EditForm?  Are you using a Gallery for each day, or is it straight columns/choices?

Perhaps a screenshot of what you are experiencing would be helpful.

The reason I ask is that there are multiple ways to go about solving what you need.  But each is different depending on your scenario.

_____________________________________________________________________________________
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!

Hi @RandyHayes 

 

Yes so I have all my column/choices in the one EditFrom. I am allowing the user to select 0,4, or 8 for any of the days of the week. The final submission must be equal to 40.

 

I have attached a screenshot of the form, hopefully this makes it a little easier for you to understand.

 

 

@JFexp 

The formula will be a bit lengthy because you have individual columns for each daily entry, but the general idea is this -

1) Put a Label control on the screen - some where you like and outside of the EditForm.  Name the Label control - lblHourSum

2) Determine the DataCardValue control for each of your DataCards.  I'm going to make a couple of guesses here based on what I believe you have for each one (i.e. these are ComboBox controls).  

So, in the datacard for Monday_Activity_1 (if you expand that datacard) you should see several controls in it.  One of them will be DataCardValuex - where x is a number.  Determine all of the DataCardValue controls in each one and then construct a formula for your lblHourSum Text property as follows (I am using sequential numbers here for each control, so replace them with the names of the controls that you determined above) :

Value(DataCardValue1.Selected.Value) + 
Value(DataCardValue2.Selected.Value) + 
Value(DataCardValue3.Selected.Value) + 
Value(DataCardValue4.Selected.Value) +
<… and so on for all the controls for Monday through Sunday …>

3) Add a Label control to the screen.  Somewhere you like outside of the EditForm.  Name the Label control lblNotice.  Set the Text property to : "Please adjust your hours, must total 40."  (or whatever you want it to say).  Set the Visible property to : !(Value(lblHourSum.Text)=40)

 

4) Set the DisplayMode of the IconAccept1 to : If(lblNotice.Visible, Disabled, Edit)

This will disable your submit icon/button if the notice about the hours is displayed (hours not 40).

 

This should give you what you are looking for.

See if that helps or if you have other questions.

 

 

 

_____________________________________________________________________________________
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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,896)