cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
azertyqwerty
Helper I
Helper I

Default of Dropdown returns value of the wrong record

Hey everyone,

 

I am new to learning PowerApps, so forgive me if my question is silly, but I can't seem to figure it out. 

 

I have a gallery with the items property set to a collection named colTest.

This collection contains two columns: Name and Number 

 

Schermafbeelding 2021-10-22 om 14.30.14.png

Then I added a DropDown with the items property set to colTest. 

When I reset this DropDown, I want it to select the second record of my collection. 

 

Schermafbeelding 2021-10-22 om 14.31.36.png

Therefore, I set the default property of this DropDown to be: LookUp(colTest; Number = "Number 2").Name

This doesn't work. When I reset this DropDown, it just selects the first record again.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@azertyqwerty 

So the thing about selecting a Dropdown default is that you only have to match string to string - AND it must be on the string being displayed.  You cannot match on a column in the Items records that is not displayed.  Unlike a combobox where you have to match record to record.

 

So, in your case, the varRecord already has what you need in it.  You can set your Default property to : varRecord.Name

 

But, given that you have non-unique names, this will not match what you want in the Dropdown.  The reason is, the Dropdown will only match the first record that contains the value you are specifying to match.  In other words, the fact that you want record #2 in your example is not relevant to the dropdown because you are ultimately deriving the Name to match...which it will - the first one.

 

My suggestion would be to augment the displayed value in the dropdown to be something that is unique - if that is at all possible.  i.e.  Name 1 (number 1) and Name 1 (number 2)

Then your Default can be :  LookUp(colTest; Number = varRecord.Number).Name & " (number " & varRecord.Number & ")"

This would match as you want.

 

The only other suggestion is to change to a combobox and then there you will be matching record to record in the DefaultSelectedItems property.  In that case the match is on the exact record and not the string text.

 

_____________________________________________________________________________________
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

6 REPLIES 6
C-Papa
Super User
Super User

Just type "Name 1" in the default

anibra
Resolver II
Resolver II

Hi , Default:"Name 2"

RandyHayes
Super User
Super User

@azertyqwerty 

First important question is - are you actually working with a Dropdown control or a Combobox.  These are two completely different things.

 

If it is a Dropdown, then is your intention to replace the Gallery with a Dropdown, or is it that you want the dropdown to display as a default the selection from the Gallery?

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

First of all, thank you for taking the time to answer my question! 

 

I am working with a DropDown, not a ComboBox.

 

When I select the first record in my Gallery, I want my DropDown to look like this:

Schermafbeelding 2021-10-23 om 16.32.32.png

 

When I select the second record in my Gallery, I want my DropDown to look like this:

Schermafbeelding 2021-10-23 om 16.31.48.png

Here is how I tried to accomplish this:

To know which record I selected, I set the OnSelect property of the icon in my Gallery on: Set(varRecord; ThisItem)

Then I set the Default property of my DropDown to be: LookUp(colTest; Number = varRecord.Number).Name

I used Number since the values in the Name column aren't unique. 

 

This LookUp doesn't seem to work since my DropDown shows me the first record, instead of the second.

 

Schermafbeelding 2021-10-23 om 16.36.14.png

 

If I were to set the Default property of my DropDown to varRecord.Number, it works as expected.

However, I want to see the Name value in my DropDown instead of the Number value. 

RandyHayes
Super User
Super User

@azertyqwerty 

So the thing about selecting a Dropdown default is that you only have to match string to string - AND it must be on the string being displayed.  You cannot match on a column in the Items records that is not displayed.  Unlike a combobox where you have to match record to record.

 

So, in your case, the varRecord already has what you need in it.  You can set your Default property to : varRecord.Name

 

But, given that you have non-unique names, this will not match what you want in the Dropdown.  The reason is, the Dropdown will only match the first record that contains the value you are specifying to match.  In other words, the fact that you want record #2 in your example is not relevant to the dropdown because you are ultimately deriving the Name to match...which it will - the first one.

 

My suggestion would be to augment the displayed value in the dropdown to be something that is unique - if that is at all possible.  i.e.  Name 1 (number 1) and Name 1 (number 2)

Then your Default can be :  LookUp(colTest; Number = varRecord.Number).Name & " (number " & varRecord.Number & ")"

This would match as you want.

 

The only other suggestion is to change to a combobox and then there you will be matching record to record in the DefaultSelectedItems property.  In that case the match is on the exact record and not the string text.

 

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

Thank you so much! 

 

I replaced the DropDown with a ComboBox and just set the SelectMultiple property to false.

Then I set the DefaultSelectedItems property to LookUp(colTest; Number = varRecord.Number).

Works like a charm! 

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.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,507)