Skip to content

Commit

Permalink
add additional ratio metric example (#6209)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 authored Oct 7, 2024
2 parents 242e689 + b4fc796 commit ef9568a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions website/docs/docs/build/ratio-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Ratio allows you to create a ratio between two metrics. You simply specify a num

The following displays the complete specification for ratio metrics, along with an example.

<File name="models/metrics/file_name.yml">

```yaml
metrics:
- name: The metric name # Required
Expand All @@ -40,11 +42,19 @@ metrics:
filter: Filter for the denominator # Optional
alias: Alias for the denominator # Optional
```
</File>
For advanced data modeling, you can use `fill_nulls_with` and `join_to_timespine` to [set null metric values to zero](/docs/build/fill-nulls-advanced), ensuring numeric values for every data row.

## Ratio metrics example

These examples demonstrate how to create ratio metrics in your model. They cover basic and advanced use cases, including applying filters to the numerator and denominator metrics.

#### Example 1
This example is a basic ratio metric that calculates the ratio of food orders to total orders:

<File name="models/metrics/file_name.yml">

```yaml
metrics:
- name: food_order_pct
Expand All @@ -55,6 +65,30 @@ metrics:
numerator: food_orders
denominator: orders
```
</File>

#### Example 2
This example is a ratio metric that calculates the ratio of food orders to total orders, with a filter and alias applied to the numerator. Note that in order to add these attributes, you'll need to use an explicit key for the name attribute too.

<File name="models/metrics/file_name.yml">

```yaml
metrics:
- name: food_order_pct
description: "The food order count as a ratio of the total order count, filtered by location"
label: Food order ratio by location
type: ratio
type_params:
numerator:
name: food_orders
filter: location = 'New York'
alias: ny_food_orders
denominator:
name: orders
filter: location = 'New York'
alias: ny_orders
```
</File>

## Ratio metrics using different semantic models

Expand Down Expand Up @@ -109,6 +143,8 @@ on

Users can define constraints on input metrics for a ratio metric by applying a filter directly to the input metric, like so:

<File name="models/metrics/file_name.yml">

```yaml
metrics:
- name: frequent_purchaser_ratio
Expand All @@ -123,6 +159,7 @@ metrics:
denominator:
name: distinct_purchasers
```
</File>

Note the `filter` and `alias` parameters for the metric referenced in the numerator.
- Use the `filter` parameter to apply a filter to the metric it's attached to.
Expand Down

0 comments on commit ef9568a

Please sign in to comment.