Converting list of dates to list of numbers, with zeroes

For each user I have a list of Stats. Each has a timestamp and a number of ounces. E.g., User A has a list of Stats:

  • 7/2/2024 00:00, 12.5oz
  • 6/30/2024 00:00, 4 oz
  • 6/26/2024 00:00, 13oz

I want to generate a list on the page that will be the datasource for a barchart of their stats over the last 7 days. So for User A, the list would be
(13, 0, 0, 0, 4, 0, 12.5) because today is 7/2/2024.

How do I generate that list efficiently on the page? I want to avoid creating lots of placeholder Stats with 0s because they’re bloating my app.

Seems like maybe the Toolbox plugin could help, but I don’t know how to write the Javascript

The clue here is to use “group by” and look for “do not skip empty dates” …. And group by day with a bucket of 1

https://manual.bubble.io/core-resources/data/operations-and-comparisons#group-by

Happily what you are trying to do is built into Bubble. :slightly_smiling_face:

Oh wow - this is so helpful. Hadn’t really thought about Group By before. Thanks!

1 Like