Creating measures based on period length and query granularity
- Dominant language
- Rust
- Stars
- 20.8k
- Forks
- 2.1k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 181
Description
**Problem**
How can I retrieve the timeDimension period and granularity for which the query is made?
To compute certain temporal averages, I need to divide measures by the period length in days.
The grain of my table is user x day (one row per day per active user). Initially, I created a countDistinct measure based on the date field. However, for a given period, when filters are applied, if all users are filtered out on a particular day, that day is not counted.
```javascript
`SELECT
*,
${FILTER_PARAMS.[Cube].timestamp.filter((from, to) => { return `DATE_FROM(DATE(${to}), DATE(${from}), DAY)`})} as period_in_days,
FROM ...`
```
I tried to create a field when defining my cube, by building a dimension and then a measure on `period_in_days`, but it doesn't work when the query has a grain. `period_in_days` still equals to the entire period, regardless of the granularity.
Contributor guide
Assessment
This issue has not been assessed yet.