Cumulative counts
shayani opened this issue · 2 comments
shayani commented
Is it possible to do cumulative counts using Rollup?
Example: count how many users exists on the application each month (cumulative):
- 2024_01 - 10 total users
- 2024_02 - 15 total users
- 2024_03 - 27 total users
- ...
Thanks!
ankane commented
Hi @shayani, two options are:
-
Do this in memory
total = 0 Rollup.series("New users").transform_values { |v| total += v; total }
-
Find / create a gem that adds a
cumulative_count
method to Active RecordUser.rollup("Cumulative users") { |r| r.cumulative_count }
shayani commented
Thanks for the reply and for this awesome gem