diff --git a/docs/docs/build/metrics-view/customize.md b/docs/docs/build/metrics-view/customize.md index 5e72ac09d07..e2fc0f06c9d 100644 --- a/docs/docs/build/metrics-view/customize.md +++ b/docs/docs/build/metrics-view/customize.md @@ -33,45 +33,3 @@ The first month of the year for time grain aggregation. The valid values are 1 t Defining security policies for your data is crucial for security. For more information on this, please refer to our [Dashboard Access Policies](/manage/security.md) -## Example - -```yaml -version: 1 #defines version -type: metrics_view # metrics_view - -title: The title of your metrics view -display_name: The display_name -description: A description -model: refernce the model or table, -database / database_schema: #not sure what this is used for. - -timeseries: your timeseries column - -smallest_time_grain: #defines the smallest time grain - -first_day_of_week: #defines first day of week -first_month_of_year: #defines first month of year - -dimensions: #your dimensions, can be copied from dashboard.yaml - - name: - label: - column/expression: - property: - description - unnest: - uri: - -measures: #your measures, can be copied from dashboard.yaml - - name: - label: - type: - expressions: - window: - per: - requires: - description: - format_preset / format_d3: - valid_percent_of_total: - -security: #your security policies can be copied from dashboard.yaml -``` \ No newline at end of file diff --git a/docs/docs/build/metrics-view/expressions.md b/docs/docs/build/metrics-view/expressions.md index 0e78444b45e..d0b00759eba 100644 --- a/docs/docs/build/metrics-view/expressions.md +++ b/docs/docs/build/metrics-view/expressions.md @@ -70,6 +70,18 @@ The syntax for fixed metrics is specific to DuckDB as an OLAP engine. ::: +### Window Functions + +In addition to standard metrics, it is possible to define running window calculations of your data whether you are looking to monitor a cumulative trend, smooth out fluctuations, etc. +In the below example, bids is another measure defined in the metrics view and we are getting the previous and current date's values and averaging them. +```yaml + - display_name: bids_1day_rolling_avg + expression: AVG(bids) + requires: [bids] + window: + #order: timestamp + frame: RANGE BETWEEN INTERVAL 1 DAY PRECEDING AND CURRENT ROW +``` ## Dimension Expressions To utilize an expression, replace the `column` property with `expression` and apply a non-aggregate sql expression. Common use cases would be editing fields such as `string_split(domain, '.')` or combining values `concat(domain, child_url)`. diff --git a/docs/docs/reference/project-files/metrics-view.md b/docs/docs/reference/project-files/metrics-view.md index 216275e5d20..9a826f88eb4 100644 --- a/docs/docs/reference/project-files/metrics-view.md +++ b/docs/docs/reference/project-files/metrics-view.md @@ -44,7 +44,8 @@ In your Rill project directory, create a metrics view, `.yaml`, fi **`measures`** — Used to define the numeric [aggregates](/build/metrics-view/metrics-view.md#measures) of columns from your data model _(required)_. - **`expression`** — a combination of operators and functions for aggregations _(required)_ - **`name`** — a stable identifier for the measure _(required)_ - - **`label`** — a label for your measure _(optional)_ + - **`display_name`** - the display name of your measure._(required)_ + - **`label`** — a label for your measure, deprecated use `display_name` _(optional)_ - **`description`** — a freeform text description of the dimension _(optional)_ - **`valid_percent_of_total`** — a boolean indicating whether percent-of-total values should be rendered for this measure _(optional)_ - **`format_d3`** — controls the formatting of this measure using a [d3-format string](https://d3js.org/d3-format). If an invalid format string is supplied, measures will be formatted with `format_preset: humanize` (described below). Measures cannot have both `format_preset` and `format_d3` entries. _(optional; if neither `format_preset` nor `format_d3` is supplied, measures will be formatted with the `humanize` preset)_ @@ -58,8 +59,28 @@ In your Rill project directory, create a metrics view, `.yaml`, fi - `currency_eur` — output rounded to 2 decimal points prepended with a euro symbol: `€` - `percentage` — output transformed from a rate to a percentage appended with a percentage sign - `interval_ms` — time intervals given in milliseconds are transformed into human readable time units like hours (h), days (d), years (y), etc. - - + - **`window`** — can be used for [advanced window expressions](/build/metrics-view/expressions), cannot be used with simple measures _(optional)_ + - **`partition`** — boolean _(optional)_ + - **`order`** — using a value available in your metrics view to order the window _(optional)_ + - **`ordertime`** — boolean, sets the order only by the time dimensions _(optional)_ + - **`frame`** — sets the frame of your window. _(optional)_ + - **`per`** - calculates the expression based on the parameter defined, cannot be used with simple measures _(optional)_ + - **`requires`** — using a value available in your metrics view to set a required parameter, cannot be used with simple measures _(optional)_ + +```yaml +measures: + - display_name: sum of measure per foo required bar + expression: sum(measure) + per: [foo] + requires: [bar] + + - name: bids_1day_rolling_avg + expression: AVG(measure) + requires: [measure] + window: + order: timestamp + frame: RANGE BETWEEN INTERVAL 1 DAY PRECEDING AND CURRENT ROW +``` **`smallest_time_grain`** — Refers to the smallest time granularity the user is allowed to view. The valid values are: `millisecond`, `second`, `minute`, `hour`, `day`, `week`, `month`, `quarter`, `year` _(optional)_. **`first_day_of_week`** — Refers to the first day of the week for time grain aggregation (for example, Sunday instead of Monday). The valid values are 1 through 7 where Monday=`1` and Sunday=`7` _(optional)_.