Skip to content

Commit 69c969d

Browse files
Update sum_distinct explanation with bullet points and ignored value note
Generated-By: mintlify-agent
1 parent e236d8c commit 69c969d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

references/metrics.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,17 @@ Consider a model containing `order_id`, `order_item_id`, and `order_shipping_cos
907907
| 2 🟩 | 5 | 20 |
908908
| 2 🟩 | 6 | 30 |
909909

910-
If you want to sum shipping costs for all orders, you need to deduplicate by `order_id`. When `order_id` is the distinct key, the first `order_shipping_cost` in ascending order will be taken for each order. In this example, order 1 🟦 contributes 10 and order 2 🟩 contributes 20 (the first value when ordered ascending), giving a total of 30:
910+
To sum shipping costs for all orders, you need to deduplicate by `order_id`:
911+
912+
- When `order_id` is the distinct key, the first `order_shipping_cost` in ascending order is taken for each order
913+
- Order 1 🟦 contributes **10**
914+
- Order 2 🟩 contributes **20** (the first value when ordered ascending)
915+
- The `order_shipping_cost` of **30** for order 2 is ignored
916+
- **Total: 30**
917+
918+
<Note>
919+
If the value you are aggregating is truly distinct based on the distinct key (e.g., each order has only one shipping cost), this won't be a problem. However, if there are multiple different values for the same distinct key, only the first value in ascending order will be used.
920+
</Note>
911921

912922
<Tabs>
913923
<Tab title="dbt v1.9 and earlier">

0 commit comments

Comments
 (0)