cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ek21
Helper I
Helper I

Counting unique items in a gallery

Hi all,

 

I'm trying to create a "Totals" page after a gallery in my app, but I need more than your regular CountRows formula - I need to be able to count the number of uniqe rows. My data is "Activities" and each row constitutes an activity run by a school. However, I need to total these numbers based on the number of schools involved. For example, I might have 10 activities run (total activities) but six schools involved because two schools ran only one activity while the others ran two activities each. I've been unsuccessful in creating a formula for this!

 

Any help much appreciated 🙂

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Mike8
Memorable Member
Memorable Member

Hello ek21,

ActivityNumberLabel_6.Text = CountRows(Distinct(DetailsGallery.AllItems,Activity))

View solution in original post

10 REPLIES 10
Sienna
Resident Rockstar
Resident Rockstar

Would you be able to provide simple table similar to yours with description what you want to sums. What columns and what rules you want when you make the sums

Hi @Sienna,

 

Thanks for the reply. My data is very simple and I hope that I can explain it as much as possible. I've attached a screenshot of my data.

As you can see from the data below, i have 21 schools who have run activities. However, only 15 unqiue regions were involved, and only 11 unique activities were run.

 

I need to be able to count the number of schools involved (which is not as simple as using CountRows against my Gallery because there are often schools who run multiple activities. I also need to count the unique regions (i.e., 15 in the example above) and the number of unique activities.

 

I also need to list these unique items (i.e., schools, activities, and regions) too. I've attached a second screenshot which is a draft of my app - in circle 1, I need a list of those schools, regions, and activities, and in circle 2 I simply need the sum of what I've described abovescreencapture-create-powerapps-studio-1516672159637.png

 

Thanks again for your help!

 

screencapture-docs-google-spreadsheets-d-10Be80g36553TNYhixUY5J0rVw11uwOtBKwLIyZYmvAw-edit-1516671768813.png

Hi @ek21

 

Have you tried using the Distinct function?

 

For the list you can add this in the Items field of 3 diiferent galleries - 

Distinct(DetailsGallery,School)
Distinct(DetailsGallery,Region)
Distinct(DetailsGallery,Activity)

 

And to count the rows -

CountRows(DetailsGallery,School) and similarly others.

 

Hope this helps!


Vivek Bavishi aka That API Guy
PowerApps and Flow MVP
Blog | Twitter | YouTube | Community Profile | GitHub



If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @ThatAPIGuy,

 

Thanks for your reply! I tried the Distinct formula, but it doesn't work as it needs a table and comes up with invalid function.

 

CountRows also doesn't work, as it counts all of the rows in the source (i.e., DetailsGallery). I do have this formula for my # Activities though, as every row in my spreadsheet counts as an individual activity.

 

Thanks again!

Sienna
Resident Rockstar
Resident Rockstar

Hi

I was looking at your table for about an 1/2 an hour and I just couldn't understood it. I really apologies for it. What do you mean by unique regions and unique activities? How can I find those unique regions and unique activities in your table what you have posted? If you have another table what specify which regions and which activities are unique then please post it so I can figure out how did you get 15 unique regions and 11 unique activities. And also from your table is not quite clear what school run multiple activities

Mike8
Memorable Member
Memorable Member

Hello ek21,

ActivityNumberLabel_6.Text = CountRows(Distinct(DetailsGallery.AllItems,Activity))

Hi @Mike8,

 

That's great, thanks so much!! Worked a treat.

 

Any chance you can help with the list items??

Mike8
Memorable Member
Memorable Member

Hello ek21,

Happy to help.
Actually vivekb has already answered both of your questions.

Create 3 Galleries (GalleryA,GalleryB,GalleryC)

GalleryA.Items = Distinct(DetailsGallery,School)
GalleryB.Items = Distinct(DetailsGallery,Region)
GalleryC.Items = Distinct(DetailsGallery,Activity)

Also you can use the source of DetailsGallery in the Distinct function instead of DetailsGallery.

Let me know if you need further help.

Ahh, I made an error while pasting the formula. Thanks for the correction @Mike8

 

@ek21 : I think you want to display all the unique items in one text box like - School A, School B, School C, etc.

To achieve this, you probably want to display the list in a label. So, set the text property of the label to

 

Concat(Distinct(DetailsGallery,School),School,", ")

Concat function joins all text values of a given column in a table.

 

You can do the same for Region and Activity

Concat(Distinct(DetailsGallery,Region),Region,", ")
Concat(Distinct(DetailsGallery,Activity),Activity,", ")

Hope this helps!


Vivek Bavishi aka That API Guy
PowerApps and Flow MVP
Blog | Twitter | YouTube | Community Profile | GitHub



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.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

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,825)