cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate V
Advocate V

Combobox with defined options and different values for each option

Hello all,

I have a question regarding combobox. So far I have used CBs with data that is from an Excel sheet with, for example, 'DISTINCT' on the items property in order to have the options on the list. However, now I want to have a CB list with defined values that are not in any part of the data, and would always be the same. In this case, I would want to have the CB list with values: "0% / 25% / 50% / 75% / 100%". How can I do this? Or do I need to create a table with those values in order for the CB to read it?

And a follow-up question I have is: when an option in the CB is chosen, how can I make it so if, for example, "25%" is chosen, when the form is saved (in an editform), instead of that, another value is saved? For example: If CB=25%, "A1"

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Super User
Super User

Re: Combobox with defined options and different values for each option

@FelipeCaru 

You can specify what you want for data in combo boxes as well as most all of the other controls.

For your case, you can set the Items property of the ComboBox to the following:

 

["0%", "25%", "50%", "75%", "100%"]

This will create a single column table data source for your combobox.  It will have a Value column (which is what you would choose to display).

 

So, later you can reference that value for any other conversions.  For example, in your Update property, you can put in logic to convert such as this:

 

Switch(comboBoxx.Selected.Value,
"0%", someOtherValueFor0,
"25%", someOtherValueFor25,
etc
)

However, another option you can choose is to define the alternate value as part of the datasource you create in the Item property.

 

 

So, for example, if conversion to numbers rather than text is what you want, then you can do something like this in the Items property:

 

Table({Value:"0%", Number:0}, 
{Value:"25%", Number:.25},
{Value:"50%", Number:.5},
{Value:"75%", Number:.75},
{Value:"100%", Number:1})

This will create a two column table with a Value text column and a Number numeric column.

Then later on in your Update, you can reference the number assigned to that value, for example:

comboBoxx.Selected.Number

 

I hope this is clear and helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Super User
Super User

Re: Combobox with defined options and different values for each option

@FelipeCaru 

Some of this will depend on which of the suggestions were implemented.  If you chose the Text only items or the table based set of records, that would assist in your answer.

 

Let's assume you took the list of text values only (first suggestion example).

First, a little simplification of the formula (just to make it easier to read):

   If(areaVar.Result="Prevencion de Riesgos" && idForm="1" && DataCardValue5.Selected.Value="0%", "4+")

This should work - in fact it would work for either choice of suggestion you took (based on how they were defined).

So, begs the question, what are the values of areaVar.Result and idForm, and is idForm a text or numeric value?

In the past, I'd say "throw a label on the screen to troubleshoot", but you can now just turn on the new "Enable formula bar result view" in the app settings and you can now see directly in your designer what those values are.

This will help tremendously in troubleshooting the issue.

 

Next (just to be complete), let's assume you took the second suggested formula - the table of value and number records. If so, your formula could be as such:

   If(areaVar.Result="Prevencion de Riesgos" && idForm="1" && DataCardValue5.Selected.Number=0, "4+")

This would work equally well.

BUT...the question still remains - if you are getting nothing, I suspect the other factors in the formula condition to be at issue.

 

To truly push this, you could change your formula to the following:

   If(DataCardValue5.Selected.Value="0%", "4+")

 

If this shows "4+", then the issue is with the other conditional evaluations.

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

6 REPLIES 6
Highlighted
Dual Super User
Dual Super User

Re: Combobox with defined options and different values for each option

If the list of values isn't too large I think the easiest way to get values in a combobox is to create a collection using the OnStart method of the app.  Put something like this into the OnStart

 

ClearCollect(CB,{Text:"25%",Value:"a1"},{Text:"50%",Value:"a2"},{Text:"75%",Value:"a3"})

 

Then Bind the Items property of the Combobox to the collection, in this case 'CB'. AS you can see I'm binding both a Text and a Value property to the combobox.  The value is what you will retrieve and store when you save the record back to the data source. When binding from an Excel datasource it makes the Text and value the same.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Super User
Super User

Re: Combobox with defined options and different values for each option

@FelipeCaru 

You can specify what you want for data in combo boxes as well as most all of the other controls.

For your case, you can set the Items property of the ComboBox to the following:

 

["0%", "25%", "50%", "75%", "100%"]

This will create a single column table data source for your combobox.  It will have a Value column (which is what you would choose to display).

 

So, later you can reference that value for any other conversions.  For example, in your Update property, you can put in logic to convert such as this:

 

Switch(comboBoxx.Selected.Value,
"0%", someOtherValueFor0,
"25%", someOtherValueFor25,
etc
)

However, another option you can choose is to define the alternate value as part of the datasource you create in the Item property.

 

 

So, for example, if conversion to numbers rather than text is what you want, then you can do something like this in the Items property:

 

Table({Value:"0%", Number:0}, 
{Value:"25%", Number:.25},
{Value:"50%", Number:.5},
{Value:"75%", Number:.75},
{Value:"100%", Number:1})

This will create a two column table with a Value text column and a Number numeric column.

Then later on in your Update, you can reference the number assigned to that value, for example:

comboBoxx.Selected.Number

 

I hope this is clear and helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Advocate V
Advocate V

Re: Combobox with defined options and different values for each option

Thank you both very much. This will help me a lot (:

Highlighted
Advocate V
Advocate V

Re: Combobox with defined options and different values for each option

@RandyHayes 

I have a follow-up new question:

In the form I have now I have 2 different columns/datacards, one with the % from the CB, and another that has a value depending on the selected one in the CB. How would I go using the value of the CB as a criteria in an IF?
It is like the previous case however it is in another datacard now.

I tried using:

If(Text('Porcentaje cumplimiento_DataCard1'.Default)="0%", "4+")

And also:

If(DataCardValue5.Selected.Value="0%", "4+")

However in both cases the box keeps empty. What am I doing wrong?

cb_depending.png

 

Highlighted
Super User
Super User

Re: Combobox with defined options and different values for each option

@FelipeCaru 

Some of this will depend on which of the suggestions were implemented.  If you chose the Text only items or the table based set of records, that would assist in your answer.

 

Let's assume you took the list of text values only (first suggestion example).

First, a little simplification of the formula (just to make it easier to read):

   If(areaVar.Result="Prevencion de Riesgos" && idForm="1" && DataCardValue5.Selected.Value="0%", "4+")

This should work - in fact it would work for either choice of suggestion you took (based on how they were defined).

So, begs the question, what are the values of areaVar.Result and idForm, and is idForm a text or numeric value?

In the past, I'd say "throw a label on the screen to troubleshoot", but you can now just turn on the new "Enable formula bar result view" in the app settings and you can now see directly in your designer what those values are.

This will help tremendously in troubleshooting the issue.

 

Next (just to be complete), let's assume you took the second suggested formula - the table of value and number records. If so, your formula could be as such:

   If(areaVar.Result="Prevencion de Riesgos" && idForm="1" && DataCardValue5.Selected.Number=0, "4+")

This would work equally well.

BUT...the question still remains - if you are getting nothing, I suspect the other factors in the formula condition to be at issue.

 

To truly push this, you could change your formula to the following:

   If(DataCardValue5.Selected.Value="0%", "4+")

 

If this shows "4+", then the issue is with the other conditional evaluations.

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Advocate V
Advocate V

Re: Combobox with defined options and different values for each option

@RandyHayes 

That was exactly what I needed. Again, thanks.

I enabled that option and saw that it was a spanish character that was messing the formula, so to speak, since "o" is not the same than "ó", hence, it was giving a false.

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (10,714)