cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

DISTINCT on a table to fill a Gallery? Nope!

 

I have an Excel table, "AppDetail", as a source for my app.
It contains several columns, one of these being "Country". I want to fill a GALLERY with the DISTINCT countries I find in this table. Ok, go! Step one: I assign the ITEMS property of the gallery the following formula:

 

Distinct(AppDetail, Country)

 

Step two: I assigne the TEXT property of the label in the gallery the value Country (i.e. the field name I DISTINCTed).

 

Super easy, isn't it? WRONG! See the result:

prob1.png

 

 

There is no error on the formula, but the "Country" value is not retrieved by the gallery: "invalid name"!Prob2.png

 

 

(EDIT: if a use the same Distinct above to fill a DROPDOWN "items" property, it works fine!)

 

Look what happens if I simply replace, in the ITEMS property of the gallery, the DISTINCT formula above with the plain "AppDetail" table, without changing anything: it works GREAT!prob3.png

 

 

I tried already what suggested in this post. Basically, I created a collection "AllCountries" like this, using the AppDetail table as source. 

 

ClearCollect(AllCountries, Distinct(AddColumns(AppDetail,"IDCountry",AppDetail.Country).IDCountry,IDCountry))

 

I put "AllCountries" on the ONVISIBLE property of the screen, I used this Collection in the ITEMS property of the gallery: same result, cannot find the IDCountry value! 

 

prob4.png

 

 

Oh gosh, where is my mistake?!? I love PowerApps but I also hate it! 🙂


Thanks folks!
Bye,

A.-

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: DISTINCT on a table to fill a Gallery? Nope!

Hey MisterMagoo,

 

Distinct always returns a single column table where the column name is "Result" by default

If you collect the results from a Distinct() action you can see this behaviour;

 

Collect(collectDistinctResults, Distinct(source, columnname))

Then go view the collection in the collection menu.

 

To retain the columnname for your sanity, you can use 

RenameColumns(Distinct(AppDetail,Country), "Result", "Country")

Then your gallery reference can be a bit more relevant with ThisItem.Country 

 

Like I said, only for your sanity and the sake of 'keeping things tidy' - but if you understand that a Distinct always returns with the column "Result" and you're happy with it, you can just reference ThisItem.Result and avoid the overhead 🙂

 

Hope this helps,

 

RT 

View solution in original post

3 REPLIES 3
Highlighted
Helper II
Helper II

Re: DISTINCT on a table to fill a Gallery? Nope!

So, while being sad for not having got any help so far :-), keeping on with my try&fail approach, I've been able to solve it!

 

Unbelievable. The original DISTINCT in the ITEMS of the Gallery is fine:

 

Distinct(AppDetail,Country)

 

The only thing is that I cannot refer to the "Country", inside the gallery elements, using "Country" as I was doing. I must use:

 

label.text = ThisItem.Result

 

It works! I still don't understand why, though. I just used what is proposed by the "ThisItem" element.

 

prob5.png

 

 

 

Highlighted
Microsoft
Microsoft

Re: DISTINCT on a table to fill a Gallery? Nope!

Hey MisterMagoo,

 

Distinct always returns a single column table where the column name is "Result" by default

If you collect the results from a Distinct() action you can see this behaviour;

 

Collect(collectDistinctResults, Distinct(source, columnname))

Then go view the collection in the collection menu.

 

To retain the columnname for your sanity, you can use 

RenameColumns(Distinct(AppDetail,Country), "Result", "Country")

Then your gallery reference can be a bit more relevant with ThisItem.Country 

 

Like I said, only for your sanity and the sake of 'keeping things tidy' - but if you understand that a Distinct always returns with the column "Result" and you're happy with it, you can just reference ThisItem.Result and avoid the overhead 🙂

 

Hope this helps,

 

RT 

View solution in original post

Highlighted
Helper II
Helper II

Re: DISTINCT on a table to fill a Gallery? Nope!

Thanks Russel!!

Helpful resources

Announcements
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,892)