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

Gallery: Default Selection Based on URL Parameter

I require the default selected item of a gallery to be set based on a URL parameter.

 

I've set the Default property of the gallery to Param("ParameterName"). This triggers the following error: "Invalid formula. Expected a value compatible with 'Items'."

 

Has anyone implemented this functionality before? I'm new to PowerApps, so I'm sure I'm missing something simple.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@swt 

This gets a little tricky!

First - you are not going to get a string parameter to match an Item.  You would need to lookup the actual Item from your source (the Gallery source) if you want to select it.

So, ideally put this formula in your Default property and this should work:

Lookup(yourDataSource, whateverColumnHasTheValue = Param("ParameterName"))

But it won't!!

 

Here is why.  Galleries (in my experience) are picky about the Default value and the items it contains.  

If your items are simple - let's just say a list of names and ID's and maybe a couple other things, then you can find it works.  But, when you are going to a datasource to fill in the gallery and then looking up the default value from that exact same list and getting the exact item returned to be your default...I will not.

 

So, I find you have to strip out all of the fields you don't use and then lookup (again strip out unused fields) and then it will match. 

So for example - let's just say your Gallery displayed 3 items - Title, Date, Desc

You can set the Items of the gallery to:

ShowColumns(yourDataSource, "Title", "Date", "Desc", "ParamID")

Then in your Default property, you can do this:

Lookup(ShowColumns(yourDataSource, "Title", "Date", "Desc", "ParamID"), ParamID = Param("ParameterName"))

 

This will work!  You will have the item you want selected in the Gallery.

 

Just keep in mind for any changes - you MUST have identical field signatures on your Items and your Default for the gallery to work - which, back to the beginning, is why your parameter as a default would have never worked.

 

 

Hope this is clear and helpful.

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

5 REPLIES 5
RandyHayes
Super User
Super User

@swt 

This gets a little tricky!

First - you are not going to get a string parameter to match an Item.  You would need to lookup the actual Item from your source (the Gallery source) if you want to select it.

So, ideally put this formula in your Default property and this should work:

Lookup(yourDataSource, whateverColumnHasTheValue = Param("ParameterName"))

But it won't!!

 

Here is why.  Galleries (in my experience) are picky about the Default value and the items it contains.  

If your items are simple - let's just say a list of names and ID's and maybe a couple other things, then you can find it works.  But, when you are going to a datasource to fill in the gallery and then looking up the default value from that exact same list and getting the exact item returned to be your default...I will not.

 

So, I find you have to strip out all of the fields you don't use and then lookup (again strip out unused fields) and then it will match. 

So for example - let's just say your Gallery displayed 3 items - Title, Date, Desc

You can set the Items of the gallery to:

ShowColumns(yourDataSource, "Title", "Date", "Desc", "ParamID")

Then in your Default property, you can do this:

Lookup(ShowColumns(yourDataSource, "Title", "Date", "Desc", "ParamID"), ParamID = Param("ParameterName"))

 

This will work!  You will have the item you want selected in the Gallery.

 

Just keep in mind for any changes - you MUST have identical field signatures on your Items and your Default for the gallery to work - which, back to the beginning, is why your parameter as a default would have never worked.

 

 

Hope this is clear and helpful.

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

@swt, can you let us know if @RandyHayes's solution answered your question?

 

Also, I noticed you used the Components label here. Did you have a question about Components?

swt
Frequent Visitor

Thanks so much for your super quick and clear solution, @RandyHayes! It worked perfectly. I would've never guessed that that much was required to get it to work. Smiley Happy

 

@Mr-Dang-MSFTI've removed the components label. I'm not familiar with all the terminology in PowerApps; I thought a gallery was considered a component.

@swt  under "normal" circumstances it would not take so much for this to work.

You had two requirements - pass a parameter, and select in a Gallery.

Pass a parameter and use it is easy.

Select in a Gallery (for any Gallery item that has some complexity) is where the trouble was.

 

Good luck on the rest of your design.

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

You're a life saver, I was pulling my hair out trying to work out why the default item wasn't getting selected - it made no sense. Then I filtered only the columns I required (ShowColumns function like you showed) and it's now bloody working!

 

Thanks again, kudos!

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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