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

How to count records with multiple instance

How to count records with multiple instance.

 

Sample Data:

Sun

Moon

Earth

Sun

Moon

Sun

 

Expected:

Sun = 3

Moon = 2

Earth = 1

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: How to count records with multiple instance

You can use the GroupBy function to group your table by that variable, and then use the CountRows function to calculate the number of items on each group. If your data is in a collection called 'coll', and the name of the column that has the sample data is 'Name', then the expression below will give you a table that has a column for the name and another with the count of items of that name.

AddColumns(
    GroupBy(coll, "Name", "ByName"),
    "Count",
    CountRows(ByName))

View solution in original post

5 REPLIES 5
Highlighted
Power Participant
Power Participant

Re: How to count records with multiple instance

Hi!

 

I guess you mean that they are all individual records, but have the same values. You can do this with CountIf - you can see the documentation here: https://powerapps.microsoft.com/en-us/tutorials/function-table-counts/

 

You can also get the distinct values, in your example you'd get only Sun, Moon and Earth. Read about Distinct here: https://powerapps.microsoft.com/en-us/tutorials/function-distinct/

 

If you have a gallery you could use both formulas to get what you want. In the gallery's Item-property you have to use the Distinct function, and then in the template part you have to have a label with the Text-property set to the CountIf, something like this:

 

CountIf(planetDB, HeavenlyBodyName = ThisItem.HeavenlyBodyName)

 

 

Good luck!

 

Highlighted
Anonymous
Not applicable

Re: How to count records with multiple instance

Hi,

 

Thanks for the reply. I want to know the record with the most number of instance (same values).

 

Thanks!

Highlighted
Power Apps
Power Apps

Re: How to count records with multiple instance

You can use the GroupBy function to group your table by that variable, and then use the CountRows function to calculate the number of items on each group. If your data is in a collection called 'coll', and the name of the column that has the sample data is 'Name', then the expression below will give you a table that has a column for the name and another with the count of items of that name.

AddColumns(
    GroupBy(coll, "Name", "ByName"),
    "Count",
    CountRows(ByName))

View solution in original post

Highlighted
Anonymous
Not applicable

Re: How to count records with multiple instance

This is not woring

Highlighted
New Member

Re: How to count records with multiple instance

This helped me to resolve a similar need, just wanted to correct the code referenced.  This is what should work (add ThisRecord. before ByName):

AddColumns(
    GroupBy(coll, "Name", "ByName"),
    "Count",
    CountRows(ThisRecord.ByName))

 

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 (3,269)