dating_platform/purchase_items.view.lookml 7 dims7 measures 3 warnings Repo files

LookML view · dating-platform

How this LookML order-item view models SKUs, quantity and average order value

At a glance

Does
Order lines from transaction_item events: order id, category, SKU, name, price and quantity. Measures are items_bought_count, sales_value, orders_count, items_per_order and average_order_value.Trust: Source-defined
Why
Basket analysis for web purchases: what was bought, how many items per order, and the value of an average order.Trust: Inferred
Breaks
3 warnings. Top: Identical order lines are merged
Grain
Intended as one row per order line. After the GROUP BY it is one row per distinct line value within an order. No primary key is declared.Trust: Inferred
Source
dating_platform/purchase_items.view.lookml 76 lines
Source: purchase_items.view.lookml L1-10
dating_platform/purchase_items.view.lookmlL1-10
- view: transaction_items  derived_table:    sql: |      SELECT        ti_orderid,        ti_category,        ti_sku,        ti_name,        ti_price,        ti_quantity      FROM ${TABLE}.events_atomic      WHERE event = 'transaction_item'      GROUP BY 1,2,3,4,5,5,6

dating-platform, purchase_items.view.lookml, lines 1-10

Shape

Trust: Source-defined

Every field as declared, with the dashboard tiles that read it. Computed from the source; nothing here is edited.

Derived table: rebuilt on a SQL trigger. Reads warehouse tables directly.

Dimensions 7

NameTypeSQLUsed byTags
order_idL19string${TABLE}.ti_orderid-
product_categoryL21string${TABLE}.ti_category-
skuL23string${TABLE}.ti_sku-
nameL25string${TABLE}.ti_name-
priceL27number${TABLE}.ti_price-
quantityL31int${TABLE}.ti_quantity-
order_itemsL34string${order_id}-derived

Measures 7

NameTypeSQLUsed byTags
distinct_skus_boughtL36count_distinct${sku}-derived
items_bought_countL39sum${quantity}-derived
sales_valueL42sum${price}-derived
orders_countL45count_distinct${order_id}-derived
items_per_orderL49number${items_bought_count} / NULLIF(${orders_count},0)::REAL-derived
average_order_valueL53number${sales_value} / NULLIF(${orders_count},0)::REAL-derived
countL57countCOUNT(*) of rows-

Relationships

Trust: Source-defined

No joins, no upstream views and no dashboard tiles reference this view. It is an island in the model.

Relationships of transaction_items
Relationships of transaction_items. Text version follows the diagram.This viewUsed by: explores, views, dashboardsbase view transaction_items explore in event_tracker
  • This Block
Text version
  • transaction_items is the base view of transaction_items: base view

Worth noticing

Average order value is computed here, not in transactions

Trust: Source-defined

average_order_value divides sales_value by orders_count. It never reads the order total from transactions.

Source: purchase_items.view.lookml L42-56
dating_platform/purchase_items.view.lookmlL42-56
  - measure: items_bought_count    type: sum    sql: ${quantity}  - measure: sales_value    type: sum    sql: ${price}  - measure: orders_count    type: count_distinct    sql: ${order_id}    detail: transaction_detail*  - measure: items_per_order    type: number    decimals: 2    sql: ${items_bought_count} / NULLIF(${orders_count},0)::REAL  - measure: average_order_value    type: number    decimals: 2    sql: ${sales_value} / NULLIF(${orders_count},0)::REAL  - measure: count    type: count  sets:

dating-platform, purchase_items.view.lookml, lines 42-56

What can change the answer 3

Caution: Identical order lines are merged

Trust: Source-defined

The derived table groups by all six selected columns. Two lines in one order with the same SKU, price and quantity collapse into one row.

What goes wrong: Items, quantity and sales are undercounted for repeat lines, so basket size reads low.

Read the guide: Primary keys and counts

Source: purchase_items.view.lookml L3-17
dating_platform/purchase_items.view.lookmlL3-17
- view: transaction_items  derived_table:    sql: |      SELECT        ti_orderid,        ti_category,        ti_sku,        ti_name,        ti_price,        ti_quantity      FROM ${TABLE}.events_atomic      WHERE event = 'transaction_item'      GROUP BY 1,2,3,4,5,5,6      ORDER BY ti_orderid    sql_trigger_value: SELECT MAX(collector_tstamp) FROM ${TABLE}.events_atomic    distkey: ti_orderid    sortkeys: ti_orderid  fields:  - dimension: order_id    sql: ${TABLE}.ti_orderid

dating-platform, purchase_items.view.lookml, lines 3-17

Caution: Sales ignore quantity

Trust: Source-defined

sales_value is SUM(price). A line with quantity 3 contributes one price.

What goes wrong: Average order value is understated for any order with multi-unit lines.

Source: purchase_items.view.lookml L42-44
dating_platform/purchase_items.view.lookmlL42-44
  - measure: items_bought_count    type: sum    sql: ${quantity}  - measure: sales_value    type: sum    sql: ${price}  - measure: orders_count    type: count_distinct    sql: ${order_id}

dating-platform, purchase_items.view.lookml, lines 42-44

Caution: The join key names a column, not a dimension

Trust: Source-defined

event_tracker joins transactions with sql_foreign_key: transaction_items.ti_orderid. The declared dimension is order_id, and the join declares no relationship.

What goes wrong: The join may not resolve, and if it does, many items per order make transaction sums fan out.

Read the guide: Join fanout

Source: event_tracker.model.lookml L19-22
dating_platform/event_tracker.model.lookmlL19-22
    sql_on: sessions.domain_userid = visitors.domain_userid- explore: visitors- explore: transactions- explore: transaction_items  joins:  - join: transactions    sql_foreign_key: transaction_items.ti_orderid- explore: session_apps

dating-platform, event_tracker.model.lookml, lines 19-22

Parser checks 1

Trust: Source-defined

Mechanical findings from parsing the LookML. They are facts about the files. The cards above explain which ones matter.

Show all 1 check
  • no-primary-key 1
    • purchase_items.view.lookml:1 transaction_items declares no primary_key.

Related

Guides built on this file

Related source files

Source model