So I'm working on a budget app that has transactions and categories and each transaction is associated with a category and a month.

On the front page I want to display something like this (and be able to show the same thing for different months):

Category name: Groceries

Expected amount: 1000$

Real amount (sum of all transactions from that category): 1000$

enter image description here

My data looks something like this:

enter image description here enter image description here

I tried looping over each categories and then sum up the transactions associated with it, but that's not efficient. I think the best would be to aggregate the sum to the categories collection when adding a transaction and store it in a field like "totalAmount" but then how would I know which month is that totalAmount from? Do I need to rethink my data structure? I'm at a loss here... any help would be very appreciated! :)

put on hold as off-topic by maxathousand, Devin, Shreyas Tripathy, locationunknown, Matt Obee Feb 12 at 15:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about Implementation are off-topic because this site is for User Experience design questions, not questions around how to implement these designs. Therefore, questions around the use of programs like Photoshop or languages such as CSS or JavaScript are off topic." – maxathousand, Devin, Shreyas Tripathy, locationunknown, Matt Obee
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Hi etienne. It seems your question is not really a UX question but more of a development/database question. You're best of migrating this question to a more suitable stackexchange if you want an answer. stackexchange.com/sites#technology – GWv Feb 12 at 9:12