cube-js / cube-js/cube

How to calculate rolling sum within a calendar year

Open
#8,975 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

At the moment, rollingWindow leading and trailing parameters supports values in the following format: (-?\d+) (minute|hour|day|week|month|year) which can be used to define the window size to the right and left of the offset.

I need to calculate the accumulated sum of parameter (income_per_mth) within a year, i.e. start calculating the accumulated parameter again with the onset of January of the following year. The granularity of the data is the month.

I tried to formulate this logic as follows:

```javascript
accum_param : {
title: 'accum_param_year',
sql: `income_per_mth`,
type: `sum`,
rolling_window: {
offset: 'end',
trailing: '1 year'
},
}
```
But it doest start over the calculation in January of the next year. It works with a granularity of a month, i.e.
it counts the accumulated parameter within 12 months, and not within a certain year. For example, for March 2024, the calculation will start from March 2023, but I need it to start from January 2024.

Please suggest how I can solve my problem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.