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
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 (8,497)