-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cumulative sum #40
Comments
@Roboroads - I was interested in this, too. I made a new collection from loop over the data returned from a Trend's Here's an example:
This should give you a new attribute called "total" to use when you loop through |
Currenty - I am not using Trend for this specific one, just created my own mysql query since mysql is faster at aggregating; Mutation::query()
->toBase()
->select([
DB::raw('EXTRACT(YEAR_MONTH FROM created_at) AS month'),
DB::raw('SUM(SUM(amount)) OVER (ORDER BY EXTRACT(YEAR_MONTH FROM created_at)) AS running_sum'),
])
->groupBy('month')
->orderBy('month')
->get() |
@Roboroads - how do you create the starting amount? Like - if I'm looking at users for the last week, I want to start with the 1000 users who signed up before the start of this week. Using the DB, I've unioned in an extra row. How would you handle the starting number? |
Hi! It would be nice if there was a way to get a cumulative sum per time unit;
Lets say I'm building a bank app and need a trend of how full someones account is, which is calculated by the sum of their mutations. The 3rd time unit in the trend should be a sum of timeunit 1,2 and 3.
The text was updated successfully, but these errors were encountered: