0
0
dbtdata~10 mins

Metric definitions and semantic layer in dbt - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a simple metric that counts orders.

dbt
metrics:
  - name: order_count
    model: orders
    label: "Order Count"
    type: [1]
Drag options to blanks, or click blank then click option'
Amax
Bsum
Caverage
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum instead of count for counting rows.
Using average or max which are for numeric aggregations.
2fill in blank
medium

Complete the code to define a metric that sums the revenue column.

dbt
metrics:
  - name: total_revenue
    model: sales
    label: "Total Revenue"
    type: [1]
    sql: revenue
Drag options to blanks, or click blank then click option'
Asum
Baverage
Ccount
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using count which counts rows, not sums values.
Using average or min which calculate different statistics.
3fill in blank
hard

Fix the error in the metric definition by completing the missing field.

dbt
metrics:
  - name: average_order_value
    model: orders
    label: "Average Order Value"
    type: sum
    sql: total_amount
    [1]: order_count
Drag options to blanks, or click blank then click option'
Aexpression
Bfilter
Ctimestamp
Ddrill_fields
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter or timestamp which are unrelated here.
Using drill_fields which is for navigation, not calculation.
4fill in blank
hard

Fill both blanks to create a semantic layer metric that filters by date and groups by customer.

dbt
metrics:
  - name: monthly_revenue
    model: sales
    label: "Monthly Revenue"
    type: sum
    sql: amount
    filters:
      - field: [1]
        operator: >=
        value: '2024-01-01'
    dimensions:
      - [2]
Drag options to blanks, or click blank then click option'
Aorder_date
Bcustomer_id
Camount
Dregion
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering on amount instead of date.
Grouping by amount or region instead of customer.
5fill in blank
hard

Fill all three blanks to define a metric with a time grain, filter, and label.

dbt
metrics:
  - name: daily_active_users
    model: user_activity
    label: [1]
    type: count
    time_grains:
      - [2]
    filters:
      - field: [3]
        operator: =
        value: 'active'
Drag options to blanks, or click blank then click option'
A"Daily Active Users"
Bday
Cstatus
Dmonth
Attempts:
3 left
💡 Hint
Common Mistakes
Using month instead of day for daily metrics.
Filtering on wrong field instead of status.