Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metricflow-commands.md #6181

Merged
merged 8 commits into from
Sep 30, 2024
24 changes: 13 additions & 11 deletions website/docs/docs/build/metricflow-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ mf query --metrics order_total,users_active --group-by metric_time # In dbt Core

<TabItem value="eg2" label="Dimensions">

You can include multiple dimensions in a query. For example, you can group by the `is_food_order` dimension to confirm if orders were for food or not.
You can include multiple dimensions in a query. For example, you can group by the `is_food_order` dimension to confirm if orders were for food or not. Note that when you query a dimension, you need to specify the primary entity for that dimension.
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

**Query**
```bash
dbt sl query --metrics order_total --group-by metric_time,is_food_order # In dbt Cloud
dbt sl query --metrics order_total --group-by primary_entity__is_food_order # In dbt Cloud
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use order_id__is_food_order instead of primary_entity__is_food_order since that's what is used in teh where clause tab

mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

mf query --metrics order_total --group-by metric_time,is_food_order # In dbt Core
mf query --metrics order_total --group-by primary_entity__is_food_order # In dbt Core
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved
```

**Result**
Expand All @@ -368,13 +368,15 @@ mf query --metrics order_total --group-by metric_time,is_food_order # In dbt Cor

You can add order and limit functions to filter and present the data in a readable format. The following query limits the data set to 10 records and orders them by `metric_time`, descending. Note that using the `-` prefix will sort the query in descending order. Without the `-` prefix sorts the query in ascending order.

Note that when you query a dimension, you need to specify the primary entity for that dimension.

**Query**
```bash
# In dbt Cloud
dbt sl query --metrics order_total --group-by metric_time,is_food_order --limit 10 --order-by -metric_time
dbt sl query --metrics order_total --group-by primary_entity__is_food_order --limit 10 --order-by -metric_time
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

# In dbt Core
mf query --metrics order_total --group-by metric_time,is_food_order --limit 10 --order-by -metric_time
mf query --metrics order_total --group-by primary_entity__is_food_order --limit 10 --order-by -metric_time
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved
```

**Result**
Expand All @@ -394,15 +396,15 @@ mf query --metrics order_total --group-by metric_time,is_food_order --limit 10 -

<TabItem value="eg4" label="where clause">

You can further filter the data set by adding a `where` clause to your query. The following example shows you how to query the `order_total` metric, grouped by `metric_time` with multiple where statements (orders that are food orders and orders from the week starting on or after Feb 1st, 2024):
You can further filter the data set by adding a `where` clause to your query. The following example shows you how to query the `order_total` metric, grouped by `is_food_order` with multiple where statements (orders that are food orders and orders from the week starting on or after Feb 1st, 2024). Note that when you query a dimension, you need to specify the primary entity for that dimension. In the following example, the primary entity is `order_id`.

**Query**
```bash
# In dbt Cloud
dbt sl query --metrics order_total --group-by metric_time --where "{{ Dimension('order_id__is_food_order') }} = True and metric_time__week >= '2024-02-01'"
dbt sl query --metrics order_total --group-by order_id__is_food_order --where "{{ Dimension('order_id__is_food_order') }} = True and metric_time__week >= '2024-02-01'"

# In dbt Core
mf query --metrics order_total --group-by metric_time --where "{{ Dimension('order_id__is_food_order') }} = True and metric_time__week >= '2024-02-01'"
mf query --metrics order_total --group-by order_id__is_food_order --where "{{ Dimension('order_id__is_food_order') }} = True and metric_time__week >= '2024-02-01'"
```

**Result**
Expand All @@ -428,16 +430,16 @@ mf query --metrics order_total --group-by metric_time --where "{{ Dimension('ord

To filter by time, there are dedicated start and end time options. Using these options to filter by time allows MetricFlow to further optimize query performance by pushing down the where filter when appropriate.


Note that when you query a dimension, you need to specify the primary entity for that dimension.
<!--
bash not support in cloud yet
# In dbt Cloud
dbt sl query --metrics order_total --group-by metric_time,is_food_order --limit 10 --order-by -metric_time --where "is_food_order = True" --start-time '2017-08-22' --end-time '2017-08-27'
dbt sl query --metrics order_total --group-by primary_entity__is_food_order --limit 10 --order-by -metric_time --where "is_food_order = True" --start-time '2017-08-22' --end-time '2017-08-27'
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved
-->
**Query**
```bash
# In dbt Core
mf query --metrics order_total --group-by metric_time,is_food_order --limit 10 --order-by -metric_time --where "is_food_order = True" --start-time '2017-08-22' --end-time '2017-08-27'
mf query --metrics order_total --group-by primary_entity__is_food_order --limit 10 --order-by -metric_time --where "is_food_order = True" --start-time '2017-08-22' --end-time '2017-08-27'
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved
```

**Result**
Expand Down
Loading