Counting Occurrences of a value within a list of Things

Hello, I have a bit of a brain teaser, and I’m not sure how to make it work with Bubble…

I have a list of “Order” Things that hold 2+ custom properties that hold a text defined as:

  • carb
  • protein
    (for example)

I’m trying to eventually get to a 2 lists of key/value pairs that counts how many times a value has appeared within each of those categories within ALL the Orders.

So the resulting lists would look something like…

  • carbs[ {Rice: 2}, {Potato: 1} ] (Rice appeared in 2 orders and potato appeared in 1 under carbs)
  • protein[ {Chicken: 1}, {Fish: 4} ] (Chicken appeared in 1 order and potato appeared in 4 under protein)

I would use these lists as Data Sources for repeating groups, so that I could finally represent this in the front-end as…

Rice… 2
Potato… 1

Chicken… 1
Fish… 4

How would I go around doing this in Bubble IO?
Is this sequence of distilling the information even good?

As long as I get the final result in the front-end, and I can extend it with more properties, I don’t mind changing the method.

Thanks in advance for the valuable help.