Skip to content

Commit

Permalink
add fill nulls width
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 committed Jan 17, 2024
1 parent 02a61ba commit 162bf7a
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 12 deletions.
2 changes: 2 additions & 0 deletions website/docs/docs/build/conversion-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The specification for conversion metrics is as follows:
| `base_property` | The property from the base semantic model that you want to hold constant. | Entity or Dimension | Optional |
| `conversion_property` | The property from the conversion semantic model that you want to hold constant. | Entity or Dimension | Optional |

Refer to [additional settings](#additional-settings) to learn how to customize conversion metrics with settings for null values, calculation type, and constant properties.

The following code example displays the complete specification for conversion metrics and details how they're applied:

```yaml
Expand Down
34 changes: 34 additions & 0 deletions website/docs/docs/build/cumulative-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This metric is common for calculating things like weekly active users, or month-
| `window` | The accumulation window, such as 1 month, 7 days, 1 year. This can't be used with `grain_to_date`. | Optional |
| `grain_to_date` | Sets the accumulation grain, such as month will accumulate data for one month. Then restart at the beginning of the next. This can't be used with `window`. | Optional |

Refer to [additional settings](#additional-settings) to learn how to customize conversion metrics with settings for null values, calculation type, and constant properties.

The following displays the complete specification for cumulative metrics, along with an example:

```yaml
Expand Down Expand Up @@ -244,3 +246,35 @@ group by
metric_time
limit 100
```

### Additional settings

Use the following additional settings to customize your conversion metrics:

- **Null conversion values:** Set null conversions to zero using `fill_nulls_with`.
<!-- **Calculation type:** Choose between showing raw conversions or conversion rate.
- **Constant property:** Add conditions for specific scenarios to join conversions on constant properties.-->

To return zero in the final data set, you can set the value of a null conversion event to zero instead of null. You can add the `fill_nulls_with` parameter to your conversion metric definition like this:

```yaml
- name: vist_to_buy_conversion_rate_7_day_window
description: "Conversion rate from viewing a page to making a purchase"
type: conversion
label: Visit to Seller Conversion Rate (7 day window)
type_params:
conversion_type_params:
calculation: conversions
base_measure: visits
conversion_measure:
name: buys
fill_nulls_with: 0
entity: user
window: 7 days
```

This will return the following results:

<Lightbox src="/img/docs/dbt-cloud/semantic-layer/conversion-metrics-fill-null.png" width="75%" title="Metric with fill nulls with parameter"/>

34 changes: 34 additions & 0 deletions website/docs/docs/build/derived-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ In MetricFlow, derived metrics are metrics created by defining an expression usi
| `filter` | Optional filter to apply to the metric. | Optional |
| `offset_window` | Set the period for the offset window, such as 1 month. This will return the value of the metric one month from the metric time. | Required |

Refer to [additional settings](#additional-settings) to learn how to customize conversion metrics with settings for null values, calculation type, and constant properties.

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

```yaml
Expand Down Expand Up @@ -157,3 +159,35 @@ bookings - bookings_7_days_ago would be compile as 7438 - 7252 = 186.
| d7_booking_change | metric_time__month |
| ----------------- | ------------------ |
| 186 | 2017-07-01 |


### Additional settings

Use the following additional settings to customize your conversion metrics:

- **Null conversion values:** Set null conversions to zero using `fill_nulls_with`.
<!-- **Calculation type:** Choose between showing raw conversions or conversion rate.
- **Constant property:** Add conditions for specific scenarios to join conversions on constant properties.-->

To return zero in the final data set, you can set the value of a null conversion event to zero instead of null. You can add the `fill_nulls_with` parameter to your conversion metric definition like this:

```yaml
- name: vist_to_buy_conversion_rate_7_day_window
description: "Conversion rate from viewing a page to making a purchase"
type: conversion
label: Visit to Seller Conversion Rate (7 day window)
type_params:
conversion_type_params:
calculation: conversions
base_measure: visits
conversion_measure:
name: buys
fill_nulls_with: 0
entity: user
window: 7 days
```

This will return the following results:

<Lightbox src="/img/docs/dbt-cloud/semantic-layer/conversion-metrics-fill-null.png" width="75%" title="Metric with fill nulls with parameter"/>
53 changes: 43 additions & 10 deletions website/docs/docs/build/ratio-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Ratio allows you to create a ratio between two metrics. You simply specify a num
| `filter` | Optional filter for the numerator or denominator. | Optional |
| `alias` | Optional alias for the numerator or denominator. | Optional |

Refer to [additional settings](#additional-settings) to learn how to customize conversion metrics with settings for null values, calculation type, and constant properties.

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

```yaml
Expand Down Expand Up @@ -61,29 +63,29 @@ The system will simplify and turn the numerator and denominator in a ratio metri

```sql
select
subq_15577.metric_time as metric_time
, cast(subq_15577.mql_queries_created_test as double) / cast(nullif(subq_15582.distinct_query_users, 0) as double) as mql_queries_per_active_user
subq_15577.metric_time as metric_time,
cast(subq_15577.mql_queries_created_test as double) / cast(nullif(subq_15582.distinct_query_users, 0) as double) as mql_queries_per_active_user
from (
select
metric_time
, sum(mql_queries_created_test) as mql_queries_created_test
metric_time,
sum(mql_queries_created_test) as mql_queries_created_test
from (
select
cast(query_created_at as date) as metric_time
, case when query_status in ('PENDING','MODE') then 1 else 0 end as mql_queries_created_test
cast(query_created_at as date) as metric_time,
case when query_status in ('PENDING','MODE') then 1 else 0 end as mql_queries_created_test
from prod_dbt.mql_query_base mql_queries_test_src_2552
) subq_15576
group by
metric_time
) subq_15577
inner join (
select
metric_time
, count(distinct distinct_query_users) as distinct_query_users
metric_time,
count(distinct distinct_query_users) as distinct_query_users
from (
select
cast(query_created_at as date) as metric_time
, case when query_status in ('MODE','PENDING') then email else null end as distinct_query_users
cast(query_created_at as date) as metric_time,
case when query_status in ('MODE','PENDING') then email else null end as distinct_query_users
from prod_dbt.mql_query_base mql_queries_src_2585
) subq_15581
group by
Expand Down Expand Up @@ -125,3 +127,34 @@ metrics:
```
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. The `alias` parameter is used to avoid naming conflicts in the rendered SQL queries when the same metric is used with different filters. If there are no naming conflicts, the `alias` parameter can be left out.

### Additional settings

Use the following additional settings to customize your conversion metrics:

- **Null conversion values:** Set null conversions to zero using `fill_nulls_with`.
<!-- **Calculation type:** Choose between showing raw conversions or conversion rate.
- **Constant property:** Add conditions for specific scenarios to join conversions on constant properties.-->

To return zero in the final data set, you can set the value of a null conversion event to zero instead of null. You can add the `fill_nulls_with` parameter to your conversion metric definition like this:

```yaml
- name: vist_to_buy_conversion_rate_7_day_window
description: "Conversion rate from viewing a page to making a purchase"
type: conversion
label: Visit to Seller Conversion Rate (7 day window)
type_params:
conversion_type_params:
calculation: conversions
base_measure: visits
conversion_measure:
name: buys
fill_nulls_with: 0
entity: user
window: 7 days
```

This will return the following results:

<Lightbox src="/img/docs/dbt-cloud/semantic-layer/conversion-metrics-fill-null.png" width="75%" title="Metric with fill nulls with parameter"/>
37 changes: 35 additions & 2 deletions website/docs/docs/build/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Simple metrics are metrics that directly reference a single measure, without any
| `type_params` | The type parameters of the metric. | Required |
| `measure` | The measure you're referencing. | Required |

Refer to [additional settings](#additional-settings) to learn how to customize conversion metrics with settings for null values, calculation type, and constant properties.

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


Expand All @@ -28,7 +30,7 @@ metrics:
- name: The metric name # Required
description: the metric description # Optional
type: simple # Required
label: The value that will be displayed in downstream tools #Required
label: The value that will be displayed in downstream tools # Required
type_params: # Required
measure: The measure you're referencing # Required

Expand All @@ -50,7 +52,7 @@ If you've already defined the measure using the `create_metric: true` parameter,
type: simple # Pointers to a measure you created in a semantic model
label: Count of customers
type_params:
measure: customers # The measure youre creating a proxy of.
measure: customers # The measure you're creating a proxy of.
- name: large_orders
description: "Order with order values over 20."
type: SIMPLE
Expand All @@ -60,3 +62,34 @@ If you've already defined the measure using the `create_metric: true` parameter,
filter: | # For any metric you can optionally include a filter on dimension values
{{Dimension('customer__order_total_dim')}} >= 20
```
### Additional settings
Use the following additional settings to customize your conversion metrics:
- **Null conversion values:** Set null conversions to zero using `fill_nulls_with`.
<!-- **Calculation type:** Choose between showing raw conversions or conversion rate.
- **Constant property:** Add conditions for specific scenarios to join conversions on constant properties.-->

To return zero in the final data set, you can set the value of a null conversion event to zero instead of null. You can add the `fill_nulls_with` parameter to your conversion metric definition like this:

```yaml
- name: vist_to_buy_conversion_rate_7_day_window
description: "Conversion rate from viewing a page to making a purchase"
type: conversion
label: Visit to Seller Conversion Rate (7 day window)
type_params:
conversion_type_params:
calculation: conversions
base_measure: visits
conversion_measure:
name: buys
fill_nulls_with: 0
entity: user
window: 7 days
```

This will return the following results:

<Lightbox src="/img/docs/dbt-cloud/semantic-layer/conversion-metrics-fill-null.png" width="75%" title="Metric with fill nulls with parameter"/>

0 comments on commit 162bf7a

Please sign in to comment.