Clause ordering and optionality
  • Required: FROM · SHOW · GROUP BY · SINCE
  • Optional: SEGMENT BY
  • Order: FROM → SHOW → GROUP BY → SINCE → SEGMENT BY
Minimal example
FROM products
SHOW SUM(total_sales)
GROUP BY product_id
SINCE -7d
Full example
FROM products
SHOW SUM(total_sales) * COUNT(quantity_purchased)
GROUP BY product_id
SINCE this_month
SEGMENT BY geo_city

Clauses

FROM

  • Purpose: Selects the dataset.
  • Example:
    FROM products
    

SHOW

  • Purpose: Lists expressions to compute. Typically uses aggregation functions over metrics or fields.
  • Examples:
    SHOW SUM(total_sales)
    SHOW COUNT(quantity_purchased), MAX(total_sales)
    SHOW COUNT(*)
    

GROUP BY

  • Purpose: Defines the grouping keys for aggregation.
  • Keys: Can be identifiers, dimensions, or product_attributes.* paths.
  • Examples:
    GROUP BY product_id
    GROUP BY product_attributes.color, product_attributes.size
    

SINCE

  • Purpose: Defines the time window for the query.
  • Accepted forms:
    • Relative: -7d, -14d, -30d, -60d, -90d, -180d, -365d, -24h, -48h, -12m, -1y
    • Keywords: today, yesterday, this_week, last_week, this_month, last_month, this_quarter, last_quarter, this_year, last_year
    • Common rolling windows: past_7_days, past_14_days, past_30_days, past_60_days, past_90_days, past_180_days, past_365_days
    • ISO: 2025-03-15 or 2025-03-15T10:30:00Z (timezone offsets supported)
  • Examples:
    SINCE -7d
    SINCE this_month
    SINCE 2025-01-01
    SINCE 2025-01-01T00:00:00Z
    

SEGMENT BY (optional)

  • Purpose: Adds an additional segmentation dimension applied to each group.
  • Examples:
    SEGMENT BY geo_country
    SEGMENT BY marketing_campaign, geo_country
    
Identifiers and paths
  • Identifiers: letters, digits, underscores; start with a letter or underscore.
  • Paths: dot notation (for example, product_attributes.color).
Literals
  • Strings: ‘value’ or “value”
  • Numbers: 10, 10.5
  • Booleans: TRUE, FALSE
Examples Group by attributes with a rolling window
FROM products
SHOW SUM(total_sales)
GROUP BY product_id, product_attributes.metafields.custom.style_code
SINCE past_30_days