cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JonathanGibbs
Level: Powered On

Populate dropdown with values as well as display texts?

Can I populate a dropdown's items with value-text pairs, rather than just texts? And then retrieve a numeric Value rather than the displayed text? in other words, emulate

<Select><Option value=1>Item 1</Option><Option Value=2>Item 2</Option><Option Value=3>Item 3</Option></Select>

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Populate dropdown with values as well as display texts?

Yes, you can do that. You can set a list (table) or objects as the items for a Dropdown control. The objects can have multiple properties, and you can select which property to display, and can access the other properties.

 

For example, if you set the value of the Items property as the following:

Table({ Text: "Item 1", Val: 1 }, { Text: "Item 2", Val: 2 }, { Text: "Item 3", Val: 3 })

You can select the value to be displayed by selecting the View / Advanced option in the ribbon. 

 DropdownItems.PNG

And in another control, you can select the "Val" property of the Selected item in your dropdown. For example, you can set the Text property of a Textbox to the following expression:

"Selected value: " & Dropdown1.Selected.Val

And if you select the option named "Item 2", the text box will display "Selected value: 2".

View solution in original post

11 REPLIES 11
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Populate dropdown with values as well as display texts?

Yes, you can do that. You can set a list (table) or objects as the items for a Dropdown control. The objects can have multiple properties, and you can select which property to display, and can access the other properties.

 

For example, if you set the value of the Items property as the following:

Table({ Text: "Item 1", Val: 1 }, { Text: "Item 2", Val: 2 }, { Text: "Item 3", Val: 3 })

You can select the value to be displayed by selecting the View / Advanced option in the ribbon. 

 DropdownItems.PNG

And in another control, you can select the "Val" property of the Selected item in your dropdown. For example, you can set the Text property of a Textbox to the following expression:

"Selected value: " & Dropdown1.Selected.Val

And if you select the option named "Item 2", the text box will display "Selected value: 2".

View solution in original post

RonAtSogeti
Level: Powered On

Re: Populate dropdown with values as well as display texts?

Is something like this also possible for a datacard. Suppose I have a Sharepoint list (1) that has a lookup field Country. Another Sharepoint list (2) contains the countries. It has 2 fields, country code and country description. In PowerApps I want to maintain list 1 and I would like to show the user the country description in the dropdown, but store the country code. Thanks in advance.

nguyenvq714
Level: Power Up

Re: Populate dropdown with values as well as display texts?

Thanks @CarlosFigueira for this.  I can confirm that the dropdown displays the "text", and after selecting an item, I can save and the "val" that is selected gets saved in the database.

 

However, when I go back to edit the same entry, I notice that the default item in the dropdown menu does not reflect what "val" is set to in the database.  As a matter of fact, it remains blank.  How do we get the dropdown menu to have what "val" is stored in the database?  Thank you.

PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Populate dropdown with values as well as display texts?

I believe that if you find a similar item from the table in the Default property of the dropdown, you should be able to get your scenario to work.

 

If your dropdown is inside a data card (which has a Default property with the value that you want selected), this formula should work (edited to add missing property reference):

Dropdown1.Default:
    Lookup(
        Table({ Text: "Item 1", Val: 1 }, { Text: "Item 2", Val: 2 }, { Text: "Item 3", Val: 3 }),
        Val = Parent.Default).Text

 

nguyenvq714
Level: Power Up

Re: Populate dropdown with values as well as display texts?

@CarlosFigueira thank you, but when I click on the DataCardValue (the dropdown box), where the Items attribute is the "Table()" list, I edited the "Default" attribute to what you suggested, but I get the error:

 

"This property expects Text values, but this rule produces incompatible Record values."

 

Do I need to somehow specify to only return the "Text" field?  Thanks.

PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Populate dropdown with values as well as display texts?

Yes, I was missing the .Text reference in the default declaration. It should be as follows:

Dropdown1.Default:
    Lookup(
        Table({ Text: "Item 1", Val: 1 }, { Text: "Item 2", Val: 2 }, { Text: "Item 3", Val: 3 }),
        Val = Parent.Default).Text
nguyenvq714
Level: Power Up

Re: Populate dropdown with values as well as display texts?

Thank @CarlosFigueira, adding in ".Text" works.

jurivera
Level: Powered On

Re: Populate dropdown with values as well as display texts?

Hi RonAtSogeti,

 

Did you ever find how to do this?

I'm faced with the exact situation.

 

Thanks in advance!

jurivera
Level: Powered On

Re: Populate dropdown with values as well as display texts?

Hey guys,

 

I solve my issue at least. Here is what i did:

 

Problem: Need to display two fields (GenderID and GenderDesc) on the same Dropdown list.

This comes from a Sharepoint list.

When I select the item, i want to save only the GenderID.

 

Solution:

In Sharepoint I changed the field "GenderID" from the list called "UCA_Gender", from length 4 to 30.
In Sharepoint I changed the field "CI_Gender" from the list called "UCA_ClientsInfo", from length 4 to 30.

DataCardGender_1.Update = Dropdown7_1.Selected.GenderID
DataCardGender_1.Dropdown7_1.Items = AddColumns(UCA_Gender, "GenderIDDesc", Concatenate(GenderID, "-", GenderDesc))
DataCardGender_1.Dropdown7_1.OnSelect = Dropdown7_1.Selected.GenderID

 

Works like a charm Smiley LOL !!!

 

If you guys need a full explanation (screeshots and such) let me know and i'll be glad to provide it in this post.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 319 members 6,177 guests
Please welcome our newest community members: