ankane/rollup

Cumulative counts

shayani opened this issue · 2 comments

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!

Hi @shayani, two options are:

  1. Do this in memory

    total = 0
    Rollup.series("New users").transform_values { |v| total += v; total }
  2. Find / create a gem that adds a cumulative_count method to Active Record

    User.rollup("Cumulative users") { |r| r.cumulative_count }

Thanks for the reply and for this awesome gem