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

Set max value depend on dropdown

Hi, i am trying to achieve simple if statement with some help of docs but i just dont know what is wrong.
I have dropdown with three options.

Every option should set max value for field. (15,50,unlimited)

A i am trying it with code in onChange

 

 

If(DataCardValue36.Selected.Value = "OPTION1" && Value(DataCardValue30.Text) > 15 ; Set(DefaultTiming;15) && Set(ResetTiming;true))

 

 

Basically i check if is option1 checked and if is number in field bigger then 15 and if yes then set that number to max number which is 15.

But it do nothing. I think problem is  that ";" should be "," but it gaves me just error.
I will be thankfull for any help.

1 ACCEPTED SOLUTION

Accepted Solutions

As noted previously, different languages handle operators and identifiers different within the studio.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/global-apps#formula-separators-and-chai...

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/operators

 

Basically, in your language that formula is not correct. Unfortunately, there's not an easy way to transcribe formulas from one language to another, so expect most people to show examples/snippets in their language.

 

If you replace the commas (,) with semi-colons (;), then you can separate the function correctly. Your language may require double semi-colons (;;) to chain functions together.

 

Given the additional details you provided, you can probably add an OnChange function to each input field so its being evaluated for each update of the field.

With(
{
    varInputMax: Switch(
        DataCardValue36.Selected.Value;
        "OPTION2";
        50;
        "OPTION1";
        15;
        1000000 // Some sort of max (something realistic)
    );
    varInputMin: 0;
    varInput: Value(Self.Text)
};
    If(varInput < varInputMin Or varInput > varInputMax, Reset(Self))
)

That would reset the text input control (Self), if it was outside the min/max value you established from the Dropdown. The switch default has some large number to keep the formula simple, and could be whatever you need it to be.

This approach would work for the inputs after the Dropdown has been set, and assumes it wouldn't change. If the Dropdown were to change, then you could use a similar formula to assess each row and reset it, if needed.

 

As you have probably gathered, you can't "set" the value of a control. However, you can have that control use a default which is a variable and set that variable another way. This can become a bit cumbersome, especially if you want/expect the users to interact with the input fields (but want to limit their inputs).

View solution in original post

6 REPLIES 6
Resolver I
Resolver I

In shown code 2 code 2 correction required, 

1. Set(var, value) (it shout be comma not 🙂

2. If you are setting 2 values inside if then ; to be used not &&

If( true, set(var1,value1); set(var2, value2))

To the first point yes you are correct I just tried it because I was getting an error with ",".
So i tried is as You said but i am getting errors again.

jurajjakubov_0-1599917342982.png

And I really don't know what is wrong.
What I want to do is on true set those two variables to different values.



@Jagadeeshk some languages use semi-colons (;) in place of commas (,) - this can cause some confusion when reviewing code blocks. Just a friendly FYI.

 

As far as what the OP is looking to accomplish, it probably depends on what this outcome is being used for. You indicate that you have a function which is:

  • Using a Dropdown control to evaluate one of three options
  • Using an input (Text Input?) control to evaluate a number
  • Based on these two controls, set global variable(s)
    • How are those variable(s) being used?
    • Does it need to to reevaluated for both a Dropdown and a Text Input change?

 

I would like to understand how the variables are being used because you may be able to forgo variables, and instead use a function that conditionally evaluates the fields.

 

For example, you can do something like

Switch(
    DataCardValue36.Selected.Value ,
    "{50 Option}"
    Min( Value(DataCardValue30.Text) , 50 ),
    "{15 Option}"
    Min( Value(DataCardValue30.Text) , 15 ),
    Value(DataCardValue30.Text) // Default to Infinite/Value
)

This will result in a number. If the Dropdown is the 50 limit, then it will use the smallest of (50, the number field), etc, etc. This can be used to set your variable, but if all you are doing is using that variable somewhere else (like to show a number, or in a patch), then you can use this formula and forgo the variables. This is an example of a behavior function. Let me know if you have any questions.

Its simple.
User can select from 3 options in the dropdown (OPTION1, OPTION2, OPTION3)
And then there are 4(text input field with number format)fields.

Then he write number in each field while this number is limited by the option from dropdown as shown below.

Variables are only context variables created with updateContext. I need them only for this.

Example.
I choose OPTION1 in the dropdown so I can write numbers only from interval 0-15 in each field. -> on submit saved to SharePoint list
I choose OPTION2 in the dropdown so I can write numbers only from interval 0-50 in each field. -> on submit saved to SharePoint list

What i tried to achive with my code was that when user writes number from outside of interval, the number will be changed to max number from interval. (it can be limited somehow different but this looked good for me)

Example.
I choose OPTION1 so i can write only numbers from 0-15 interval. But I write 18. So it will automatically change to max which is 15.

And to your code, I don't understand why is everything black after the first argument it happens to me often.

 
 
 
 
 

xxx.png

 

Thanks for Your time.

As noted previously, different languages handle operators and identifiers different within the studio.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/global-apps#formula-separators-and-chai...

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/operators

 

Basically, in your language that formula is not correct. Unfortunately, there's not an easy way to transcribe formulas from one language to another, so expect most people to show examples/snippets in their language.

 

If you replace the commas (,) with semi-colons (;), then you can separate the function correctly. Your language may require double semi-colons (;;) to chain functions together.

 

Given the additional details you provided, you can probably add an OnChange function to each input field so its being evaluated for each update of the field.

With(
{
    varInputMax: Switch(
        DataCardValue36.Selected.Value;
        "OPTION2";
        50;
        "OPTION1";
        15;
        1000000 // Some sort of max (something realistic)
    );
    varInputMin: 0;
    varInput: Value(Self.Text)
};
    If(varInput < varInputMin Or varInput > varInputMax, Reset(Self))
)

That would reset the text input control (Self), if it was outside the min/max value you established from the Dropdown. The switch default has some large number to keep the formula simple, and could be whatever you need it to be.

This approach would work for the inputs after the Dropdown has been set, and assumes it wouldn't change. If the Dropdown were to change, then you could use a similar formula to assess each row and reset it, if needed.

 

As you have probably gathered, you can't "set" the value of a control. However, you can have that control use a default which is a variable and set that variable another way. This can become a bit cumbersome, especially if you want/expect the users to interact with the input fields (but want to limit their inputs).

View solution in original post

Thanks for your patience, it works. But that think with semicolon and comma its pretty weird it should be united.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (83,325)