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

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
Super User
Super User

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
MisterMagoo
Level: Powered On

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

 

 

 

Super User
Super User

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

MisterMagoo
Level: Powered On

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

Thanks Russel!!

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 (Last 30 Days)
Users online (6,786)