cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to show only distinct items in a gallery?

This seems very simple, but I cannot get it to work.

 

I have approx 20 items in a static data source (excel table), "Benchmark_Test", which are grouped under 5 categories, under the column "Parent".

 

I am trying to show only 5 distinct items in the gallery, 1 for each parent. So 1 item should display Parent1, the 2nd should display "Parent2", etc.

 

The following code, under 'items' for the gallery, does not work owing to the equals sign.

ilter(Benchmark_Test,Parent=Distinct(Benchmark_Test,thisitem.parent))

Any ideas? Thanks 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @Anonymous ,

Do you want to the Parent field display non-repeatingly?

Just setting the gallery's Items to this is ok.

Distinct(Benchmark_Test,Parent)

However, the gallery will only display the data of Parent, without other fields.

Distinct function will return a table with only one field named Result to display the Parent field non-repeatingly.

I think that's not what you need.

Do you want to display other fields at the same time?

If so, I suggest you try GroupBy function.

This function could be used to group table based on Parent field. In this way, the Parent field data will not repeat, other fields'data will be retained at the same time.

I've made a similar test for your reference:

1)insert one gallery

Set the gallery's Items:

GroupBy(Benchmark_Test,"Parent","otherdata")  

2)insert a gallery inside the gallery

set the gallery2's Items:

ThisItem. otherdata                  //this gallery will display the data that have the same parent 


1017_LI.jpg

 

10172_LI.jpg

Here's a doc about GroupBy function for your reference:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-groupby

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
CarlosFigueira
Power Apps
Power Apps

You can use this expression for the Items property of the gallery:

Distinct(Benchmark_Test, Parent)

The Distinct function returns a table with a single column (called 'Result') that contains the distinct values for the given expression (in the example above, the values of the 'Parent' column).

Hope this helps!

v-yutliu-msft
Community Support
Community Support

Hi @Anonymous ,

Do you want to the Parent field display non-repeatingly?

Just setting the gallery's Items to this is ok.

Distinct(Benchmark_Test,Parent)

However, the gallery will only display the data of Parent, without other fields.

Distinct function will return a table with only one field named Result to display the Parent field non-repeatingly.

I think that's not what you need.

Do you want to display other fields at the same time?

If so, I suggest you try GroupBy function.

This function could be used to group table based on Parent field. In this way, the Parent field data will not repeat, other fields'data will be retained at the same time.

I've made a similar test for your reference:

1)insert one gallery

Set the gallery's Items:

GroupBy(Benchmark_Test,"Parent","otherdata")  

2)insert a gallery inside the gallery

set the gallery2's Items:

ThisItem. otherdata                  //this gallery will display the data that have the same parent 


1017_LI.jpg

 

10172_LI.jpg

Here's a doc about GroupBy function for your reference:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-groupby

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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