Qk! Let's try again (it is not midnight anymore for me!).
This doesn't affect your current task (getting sum of last 3 months) much, but generally a better design will be like (it works better when you need to query various data):
FirstOfMonth AmountType AmountValue
07/01/22 Type01 $345.65
07/01/22 Type02 $523.44
...
07/01/22 Type20 $???.??
08/01/22 Type01 $622.90
...
08/01/22 Type20 $???.??
09/01/22 Type01 $250.00
09/01/22 Type02 $762.23
09/01/22 Type03 $399.22
...
09/01/22 Type20 $???.??
To get total of last 3 months (the current one included) for certain amount type you run a query like:
Code:
SELECT SUM(AmountValue) FROM YourTable WHERE AmountType = QueriedAmountType AND FirstOfMonth BETWEEN DateSerial(YEAR(Date(),MONTH(Date())-2,1) AND DateSerial(YEAR(Date(),MONTH(Date()),1)
To get totals of last 3 months (the current one included) for all amount types you run a query like (the column CurrentMonth in result is optional):
Code:
SELECT DateSerial(YEAR(Date(),MONTH(Date()),1) AS CurrentMonth, AmountType, SUM(AmountValue) FROM YourTable WHERE FirstOfMonth BETWEEN DateSerial(YEAR(Date(),MONTH(Date())-2,1) AND DateSerial(YEAR(Date(),MONTH(Date()),1) GROUP BY AmountType