Count top 10 in db

I finally decided to sit down and try making a webapp in Appgyver and things a slowly coming together…
I have a db with names (db in Appgyver)
In the image below all names are shown but there is two names that are the same (“nr 2”).

I want to make a “top 10 names” of most used.

  • a list/table where the same name is only shown once, and then have a counter next to it.

How do I go about that?

Hi, I would suggest you look into the GROUP (docs) formula function to first group the items by name, then you can manipulate the list further with for example MAP. Here is the reference for all formulas available for lists.

I got to this…
In the Primary label of my List I made this formular (based on what I understood from the docs and from other answers on the forum), but it is not working.

My NameDB2 is a data variable - Collection of data records, based on my database “NameDB”.
There is at the moment three columns: id, Name, Type.

First I make a Name group, I then put it inside a MAP to get an array.

What format do you want the data to be in at the end? Just a list of the 10 most popular names?

I want to display the names and a count of the same names -sorted descending so the most used name is at the top.

I might later make 4 lists filtered for the 4 machineTypes I have, so each get a separate list. But that is in the future.

Hi, there’s an example in the docs like this:

GROUP(allProducts, item.category, key + " category contains " + COUNT(items) + " product(s)")

["Utility category contains 2 product(s)","Tools category contains 1 product(s)"]

So in your case

GROUP(data.NameDB2, item.Name, {name: key, count: COUNT(items)})

Then you can use SORT_BY_KEY to get it in order and SLICE to get items 1-10 :slight_smile:

1 Like

I did see the example but when I could not get it to work I ended up with the previous screenshot…

It is still not working. Is it because I am binding it to the Primary label in a list?

Hi, yes that’s the problem, you cannot bind a list of objects to a text.

1 Like

Thank you @Mari for being patient with me :slight_smile:
I got it to work. I was looking for the error in the formula but I needed to work with the repeat with :slight_smile:

1 Like

Hi all. I have a similar goal to Helmar’s goal (I think)
I have a list of people’s initials and “points” they have earned with various tasks they complete.
I want to display each person’s initials and the total sum of the points they have earned (well actually only the people with the top 5 cumulative point values).
I’ve successfully used the group function but am stuck as to how to list the group by descending cumulative point values.
Any help would be appreciated, thanks!