cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Coopedup
Resolver II
Resolver II

Set form field value based on others value

Hi,

 

I've got a form that has fields that I want to user to enter, numerical values in a drop down (1-5). I've then setting a score field based on a sum of the two selectable field. Then based on the sum will define the level (Low, Medium or High). 

 

For the score field I set the DataCardValues default value from the sum and then failing to set the rating field (if 0-4, Low. 5-10, Medium. 11-25, High).

 

Sum(DataCardValue422.Selected.Value * DataCardValue421.Selected.Value)

A quick test and I get an error message 

Coopedup_0-1609951095129.png

 

If(
    DataCardValue424 < 5, "Low","High"
)

  

9 REPLIES 9
RandyHayes
Super User
Super User

@Coopedup 

In your formula, you are referring to the control...not to the value of the control.

I am not sure if you are stating the DataCardValue424 is a Label or a dropdown.  If it is a dropdown, then the following formula is needed:

If(
    DataCardValue424.Selected.Value < 5, "Low","High"
)

If it is a label, then the following:

If(
    Value(DataCardValue424.Text) < 5, "Low","High"
)

 

You always need to refer to the property of the control that contains the value you want and not just to the control.  Unfortunately, in the designer, sometimes just referring to the control works (erroneously), but in Play mode it will fail.

 

I hope this is helpful for you.

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

So I'd tried the value option previously and got an error, though I think the problem is that the field being set to Low or High would normally be a drop down list so I have to select the required value and not set a text value!

RandyHayes
Super User
Super User

@Coopedup 

I'm actually a little confused on which control type you are setting and what you are getting it from.

If you are trying to set a dropdown that has "Low", "High" in it, then you would be setting the Default property of that dropdown with the previous formulas.

If you are setting a Text label, then the formula is fine in the Text property of the label.

 

If DataCardValue424 is a dropdown and .Selected.Value is not available, then what is the Items property of that control?  .Value refers to a column in the items property of the control...so, if you are using a record source or a function that doesn't return Value tables, then you will not see that option...you would choose whichever is appropriate based on the Items property.

_____________________________________________________________________________________
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!
Coopedup
Resolver II
Resolver II

confusing others is quite a skill I have! 

 

So I'm attempting to chose the Dropdown value and though the if statement validates correctly, I've also successfully tested on normal label which you see in the screen shot, there is still an error on the very simple formula (in this example value 2 is being validated as less than 5 so equals Low).

 

Coopedup_0-1609955296436.png

 

Coopedup_1-1609955643296.png

 

 

RandyHayes
Super User
Super User

@Coopedup 

Couple questions

1)  Is this a Combobox or a Dropdown?  Please verify

2) What property are you trying to set on that control?  Your image does not show the property, just the formula.

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

This is actually a Combo box in a form which takes its list of options from a SP List choice field.  I was wanting to set the Default based on the value of another field...in the end once its updating I'll set it as Display only.

RandyHayes
Super User
Super User

@Coopedup 

So, first, a ComboBox is extreme for this purpose and only adds complexity.  A dropdown would be a better choice.

The main reason is that to set Defaults on a ComboBox (which you can only do on the DefaultSelectedItems property), you need to provide a Record.  So, your formula will never work as it is providing a Text value, not a record.

 

This all appears to be in a Form.  So that would explain the combobox as it would choose that as a default control type...so...

If you want to keep the control type as a the combobox, then you need to set this formula in the DefaultSelectedItems property of the combobox to the following:

{
   Value: If(DataCardValue424.Selected.Value < 5, "Low","High")
}

 

Note: this does not account for the ability to display the value of a record that has already been written (i.e. you're editing a record)

 

 

_____________________________________________________________________________________
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!
Coopedup
Resolver II
Resolver II

Despite all the wonderful support and help, I just couldn't get the fields to populate as I wanted (needed). With that I've moved away from workaround and changed the source (away from SP List Choices field) to be a simple text field that I now control from the p.App. 

 

What I've learnt is start with the right data and structure to begin with and then building your app is easier without "workarounds".

 

Thanks (again).

 

Neil 

RandyHayes
Super User
Super User

@Coopedup 

Absolutely - the data structure is highly important to the simplicity of your App.  Text and Number columns are your friends.  Complex types are friends, but not your best friends.

_____________________________________________________________________________________
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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,267)