BigQuery Sample Queries
Overview
These 55 queries run against the UltraCart Data Warehouse (BigQuery) as written, once you point them at your own project. They are grouped into nine pages by subject, so you can read a whole page on auto orders or upsells rather than scrolling one long list. Every query on every page is listed under Find a query below.
Nothing here is a starting template you have to finish. Each query returns a result on its own, and each one names what it returns before the SQL, so you can decide whether it answers your question without reading the whole statement first.
If you would rather describe the report you want in plain English than write SQL, the in-app AI-Powered Report Builder generates the query for you, and AI Reporting with Claude Code does the same from the command line and keeps the result in version control.
Before you run a query
Three things differ between these examples and your account.
The project and dataset names. The examples were written at different times against different
accounts, so they refer to their tables in several ways: `my-data-warehouse.my_dataset.uc_orders`,
`my-data-warehouse.ultracart_dw.uc_orders`, or a bare `ultracart_dw.uc_orders`. Replace
the project and dataset with your own before running anything. Your project ID follows the pattern
ultracart-dw-{merchantid}, and you will find it under
Configuration → Developer → Data Warehouse (BigQuery).
The dataset decides what you can see. The dataset name carries the data access level, so
ultracart_dw_medium exposes plain-text customer email where ultracart_dw exposes only
billing.email_hash. You can query only the datasets your account has been granted, so a query that
names a higher level than you hold will not run. The
Data Sets and Streaming section of the parent page maps each
dataset to its level.
Queries cost money to run. BigQuery bills for bytes scanned, so a query over the full order or session history is not free. Cohort and analytics-session queries are the expensive ones here. Check the byte estimate the BigQuery console shows for a query before running an unfamiliar one against a large account.
If you are writing your own queries against these tables, learn CROSS JOIN UNNEST and the rest of
Google's array operations
first. UltraCart data is deeply nested: an order holds its items, payments, and coupons as arrays
inside the order row, and almost every query in this library flattens one of them.
Find a query
Each page below opens with what its tables hold and how they nest, then lists its queries.
Order and Revenue Queries
- Adding EST time zone dates to orders
- Revenue Per Item Over a Certain Time Period
- Orders For Specific Items Shipped By a User on a Specific Date
- Orders with a Specific Custom Field Value
- Find Order Id by Transaction Value
- Count of Apple Pay/Google Pay/Microsoft Pay Transactions
- Coupon Usage Summary
- Coupon Usage Detail
- Order Count and Revenue by Hour of Day
- Last X Replacement Shipment Order Ids and Placed By
- Replacement Shipment Count by User for a Period of Time
Auto Order Queries
- Adding Calculations to Auto Orders
- Active Auto Order Next Rebill
- Auto Orders with a Pre-shipment Notice More Than a Week Before Shipment
- Auto Orders with Missed Pre-shipment Notices
- Auto Order Logs Messages After Pre-shipment Notice and Before Shipment Should Take Place
- Auto Order Future Predictions
- Auto Order LTV Calculation
- Auto Order Percentages with CC vs PayPal 30 Day Moving Averages
Cohort and Churn Queries
- Auto Order Weekly Cohort by Main Item Id
- Auto Order Churn Overall
- Auto Order Churn by Item
- Customer Cohort Revenue
- Auto Order Cohort Revenue
- Auto Order Cohort Active Count
- Auto Order Cohort Active Percentage
Combined Auto Order Cohort Analysis
Customer, LTV, and Loyalty Queries
- Customer LTV Modeling
- Extract a Marketing List from Order History
- Projected Future Revenue Based Upon Initial Item Purchased (Non-Auto Orders)
- New Customers in a Specific Date Range By Email
- Repeat Customer Rate
- Wholesale Customer Profile LTV
- Loyalty Balance (Points based Program)
- Loyalty Balance (Store Credit Based Program)
Affiliate, UTM, and Analytics Queries
- Affiliate Metrics
- Affiliate Click to Order Metrics
- All UTMs for an Order
- UTM Sales By Week
- UTM Clicks and Weighted Revenue
- Conversion Rate from Analytics Sessions
- Page View History
StoreFront and Upsell Queries
- Order ID Experiment Variations
- List All Upsell Paths, Variation and Upsells
- Upsell Screenshot List
- Order Upsells
- StoreFront Experiment Statistics
- Upsell Path Statistics
- Find Upsell Offers Containing Text
- Upsell Statistics by Offer and Path (across all linked accounts)
Item and Inventory Queries
Project Administration Queries
Related Documentation
- Data Warehouse (BigQuery) covers access, pricing, data security, and the data model these queries read.
- AI Reporting with Claude Code turns a plain-language question into a query like these, then schedules and delivers the result.
- Data Warehouse (BigQuery) to Google Sheets puts the output of any of these queries into a sheet that refreshes itself.
- BigQuery Data Warehouse SDK runs these queries from Node.js and returns UltraCart SDK objects.