Rails model for aggregate data instead of a real table
I agree with you that this does not really fit a service nor a model. This might be more like a Query object.
class MonthlyUsageQuery
  def intialize(relation: Project.all)
    @relation = relation
  end

  def all
    relation.select(select_monthly_data_and_dates)
      .group('year', 'month', '&quot;projects&quot;.&quot;id&quot;')
  end

  private
  
  attr_reader :relation

  def select_monthly_data_and_dates
    &lt;&lt;~SQL.squish
      &quot;projects&quot;.&quot;id&quot; AS &quot;project_id&quot;,
      SUM(&quot;usages&quot;.&quot;usage&quot;) AS &quot;monthly_usage&quot;,
      date_part('year', &quot;usages&quot;.&quot;timestamp&quot;)::INT AS &quot;year&quot;,
      date_part('month', &quot;usages&quot;.&quot;timestamp&quot;)::INT AS &quot;month&quot;
    SQL
  end
end

MonthlyUsage.all
MonthlyUsage.new(relation: Project.where(name: 'Stackoverflow')).all

https://medium.com/selleo/essential-rubyonrails-patterns-part-2-query-objects-4b253f4f4539
https://medium.flatstack.com/query-object-in-ruby-on-rails-56ea434365f0