obt_* (One Big Tables): Best starting point for most analyses. Pre-joined, business-ready.
fct_* / dim_*: Granular building blocks for custom joins.
rpt_*: Pre-aggregated for specific reporting use cases.
Start with obt_ tables when possible. They’re designed as a semantic layer and handle most common joins for you.
Recommended approach
1. Start with OBT tables
For most custom analyses, obt_orders and obt_customers provide everything you need:
-- Example: Custom cohort analysisWITH first_valid_order AS ( SELECT sm_customer_key, MIN(order_processed_at) AS first_valid_order_processed_at FROM `your_project.sm_transformed_v2.obt_orders` WHERE is_order_sm_valid = TRUE GROUP BY 1)SELECT DATE_TRUNC(DATE(first_valid_order_processed_at), MONTH) AS cohort_month, COUNT(DISTINCT o.sm_customer_key) AS customers, SUM(o.order_net_revenue) AS net_revenueFROM `your_project.sm_transformed_v2.obt_orders` oJOIN first_valid_order f ON o.sm_customer_key = f.sm_customer_keyWHERE o.is_order_sm_valid = TRUEGROUP BY 1ORDER BY 1
2. Join fact + dimension tables for granular needs
When OBTs don’t have the grain you need:
-- Example: Order line-level analysis with product detailsSELECT order_id, product_title, order_line_net_revenue, product_typeFROM `your_project.sm_transformed_v2.obt_order_lines`WHERE is_order_sm_valid = TRUE AND order_line_id IS NOT NULL -- product lines only, not the order-level row
3. Use report tables for pre-aggregated metrics
Don’t re-aggregate what’s already computed:
-- Example: Daily ad performance already aggregatedSELECT date, sm_channel, ad_spend, ad_platform_reported_revenue, SAFE_DIVIDE(ad_platform_reported_revenue, ad_spend) AS roasFROM `your_project.sm_transformed_v2.rpt_ad_performance_daily`WHERE date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
Common join keys
Table Type
Primary Key
Common Join Keys
Orders
sm_order_key
sm_customer_key, sm_store_id, source_system
Order Lines
sm_order_line_key
sm_order_key, sm_product_variant_key
Customers
sm_customer_key
sm_store_id, source_system
Products
sm_product_variant_key
product_id, variant_id
Always filter by sm_store_id (SourceMedium store identifier) when working across brands or stores to avoid cross-contamination.
Best practices
Filter to valid orders
Always include is_order_sm_valid = TRUE to exclude test orders, cancelled orders, and other invalid transactions:
SELECT COUNT(*) AS valid_ordersFROM `your_project.sm_transformed_v2.obt_orders`WHERE is_order_sm_valid = TRUE;
Use consistent revenue definitions
Pick one and stick with it across your models:
order_net_revenue: After discounts and refunds, excluding shipping, taxes, and shipping taxes
order_total_revenue: Net revenue plus net shipping, net taxes, and net shipping taxes
order_gross_revenue: Before discounts and refunds
Partition and cluster your models
If creating persistent tables, optimize for query performance:
CREATE TABLE `your_project.your_dataset.custom_model`PARTITION BY DATE(order_created_at)CLUSTER BY sm_store_id, sm_channelAS ( SELECT ...)
Common patterns
Customer-level aggregations
SELECT sm_customer_key, MIN(order_created_at) AS first_order_date, MAX(order_created_at) AS last_order_date, COUNT(DISTINCT sm_order_key) AS order_count, SUM(order_net_revenue) AS lifetime_revenueFROM `your_project.sm_transformed_v2.obt_orders`WHERE is_order_sm_valid = TRUEGROUP BY 1
Channel attribution analysis
SELECT sm_channel, sm_sub_channel, COUNT(DISTINCT sm_order_key) AS orders, SUM(order_net_revenue) AS revenueFROM `your_project.sm_transformed_v2.obt_orders`WHERE is_order_sm_valid = TRUE AND DATE(order_created_at) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)GROUP BY 1, 2ORDER BY revenue DESC
Product affinity (what’s bought together)
SELECT a.product_title AS product_a, b.product_title AS product_b, COUNT(DISTINCT a.sm_order_key) AS co_purchase_countFROM `your_project.sm_transformed_v2.obt_order_lines` aJOIN `your_project.sm_transformed_v2.obt_order_lines` b ON a.sm_order_key = b.sm_order_key AND a.sm_order_line_key < b.sm_order_line_keyWHERE a.is_order_sm_valid = TRUE AND a.order_line_id IS NOT NULL -- product lines only, not the order-level row AND b.order_line_id IS NOT NULLGROUP BY 1, 2HAVING co_purchase_count >= 10ORDER BY co_purchase_count DESC
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"SourceMedium","colors":{"primary":"#A084FC","light":"#BAA6FC","dark":"#A084FC"},"logo":{"light":"https://mintcdn.com/sourcemedium/OjSPvBj0a9ize7d2/logo/light.png?fit=max\u0026auto=format\u0026n=OjSPvBj0a9ize7d2\u0026q=85\u0026s=ba06a2e9bd59b5f68b0d9a5293f04a59","dark":"https://mintcdn.com/sourcemedium/OjSPvBj0a9ize7d2/logo/dark.png?fit=max\u0026auto=format\u0026n=OjSPvBj0a9ize7d2\u0026q=85\u0026s=5e84a70aace4dd33fa1c91426acce72a","href":"https://sourcemedium.com"},"favicon":"https://mintcdn.com/sourcemedium/pt-qB7Ich-aAP65i/favicon.png?fit=max\u0026auto=format\u0026n=pt-qB7Ich-aAP65i\u0026q=85\u0026s=0f2c4639e64047f9b27d40e07f581618","appearance":{"default":"light","strict":false},"navbar":{"links":[{"href":"https://sourcemedium.com/case-study/","label":"Customer stories"},{"href":"https://sourcemedium.com/docs/data-inputs/platform-integration-instructions/all-available-integrations","label":"Integrations"}],"primary":{"type":"button","label":"Get started","href":"https://sourcemedium.com/request-demo"}},"footer":{"socials":{"twitter":"https://twitter.com/sourcemediumhq","linkedin":"https://www.linkedin.com/company/sourcemedium"}},"seo":{"metatags":{"canonical":"https://sourcemedium.com/docs"}},"integrations":{"ga4":{"measurementId":"G-LKSGE9NY1B"},"posthog":{"apiKey":"phc_yEZthPWGFIyJz42b7EPyqO7lPFRzjvDBJaw21cDcRmX","apiHost":"https://us.i.posthog.com","sessionRecording":true}},"errors":{"404":{"redirect":false,"title":"That page moved or no longer exists","description":"Try the [docs home](/index) to pick a section, [search the glossary](/help-center/glossary) for a term, or [open a support request from your workspace](/product-tours/get-support)."}},"contextual":{"options":["copy","view","chatgpt","claude"],"display":"header"},"styling":{"latex":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"sourcemedium","hasAudioNarration":false,"actualSubdomain":"sourcemedium","customDomains":["docs.sourcemedium.com"],"gitSource":{"type":"github","owner":"source-medium","repo":"sourcemedium-docs","deployBranch":"master","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true,"edits":false,"issues":false,"agentFeedback":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"},"WEB_MCP":{"status":"DISABLED"},"NARRATION":{"status":"DISABLED"}},"buildId":"6b034f0c0d7e8ddc263963cd","clientVersion":"0.0.4277","searchFilterCounts":[{"language":"default","tag":"Connect","count":109},{"language":"default","tag":"Warehouse","count":74},{"language":"default","tag":"Tables","count":51},{"language":"default","tag":"Dashboards","count":45},{"language":"default","tag":"sm_transformed_v2","count":42},{"language":"default","tag":"Data Studio dashboard","count":28},{"language":"default","tag":"Marketing \u0026 Advertising","count":28},{"language":"default","tag":"How your data works","count":26},{"language":"default","tag":"Dashboard modules","count":21},{"language":"default","tag":"Ecommerce \u0026 Subscription","count":21}]},"assistantConfig":{},"basePath":"/docs","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[]}
{"page":{"pagePath":"data-activation/managed-data-warehouse/modeling","slug":"/data-activation/managed-data-warehouse/modeling","pageMetadata":{"title":"Modeling with SourceMedium","description":"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries","icon":"cubes","href":"/data-activation/managed-data-warehouse/modeling"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Tip,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`Extend SourceMedium’s data models by building your own tables, views, or queries in your Managed Data Warehouse.`}),`\n`,_jsx(Heading,{level:`2`,id:`before-you-start`,children:`Before you start`}),`\n`,_jsxs(_components.p,{children:[`Understand `,_jsx(_components.a,{href:`/data-transformations/philosophy#table-shapes`,children:`our table types`}),`:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`obt_*`})}),` (One Big Tables): Best starting point for most analyses. Pre-joined, business-ready.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`fct_*`})}),` / `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`dim_*`})}),`: Granular building blocks for custom joins.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`rpt_*`})}),`: Pre-aggregated for specific reporting use cases.`]}),`\n`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`Start with `,_jsx(_components.code,{children:`obt_`}),` tables when possible. They’re designed as a semantic layer and handle most common joins for you.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`recommended-approach`,children:`Recommended approach`}),`\n`,_jsx(Heading,{level:`3`,id:`1-start-with-obt-tables`,children:`1. Start with OBT tables`}),`\n`,_jsxs(_components.p,{children:[`For most custom analyses, `,_jsx(_components.code,{children:`obt_orders`}),` and `,_jsx(_components.code,{children:`obt_customers`}),` provide everything you need:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`19`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`19`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- Example: Custom cohort analysis`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WITH`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` first_valid_order `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` SELECT`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sm_customer_key,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` MIN`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(order_processed_at) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` first_valid_order_processed_at`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_orders`\"})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` WHERE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_order_sm_valid `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TRUE`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` GROUP BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` DATE_TRUNC(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`DATE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(first_valid_order_processed_at), `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`MONTH`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cohort_month,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` COUNT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`DISTINCT`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` o`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_customer_key`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` customers,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` SUM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`o`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`order_net_revenue`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` net_revenue`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_orders`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` o`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`JOIN`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` first_valid_order f`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` ON`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` o`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_customer_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` f`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_customer_key`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` o`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`is_order_sm_valid`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TRUE`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`GROUP BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`ORDER BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`2-join-fact-+-dimension-tables-for-granular-needs`,children:`2. Join fact + dimension tables for granular needs`}),`\n`,_jsx(_components.p,{children:`When OBTs don’t have the grain you need:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- Example: Order line-level analysis with product details`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` order_id,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` product_title,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` order_line_net_revenue,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` product_type`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_order_lines`\"})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_order_sm_valid `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TRUE`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` AND`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` order_line_id `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`IS NOT NULL`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` -- product lines only, not the order-level row`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`3-use-report-tables-for-pre-aggregated-metrics`,children:`3. Use report tables for pre-aggregated metrics`}),`\n`,_jsx(_components.p,{children:`Don’t re-aggregate what’s already computed:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- Example: Daily ad performance already aggregated`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` date`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sm_channel,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ad_spend,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ad_platform_reported_revenue,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` SAFE_DIVIDE(ad_platform_reported_revenue, ad_spend) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` roas`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.rpt_ad_performance_daily`\"})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` date`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` >=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` DATE_SUB(CURRENT_DATE(), INTERVAL `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`30`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` DAY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`common-join-keys`,children:`Common join keys`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Table Type`}),_jsx(_components.th,{children:`Primary Key`}),_jsx(_components.th,{children:`Common Join Keys`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Orders`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`sm_order_key`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`sm_customer_key`}),`, `,_jsx(_components.code,{children:`sm_store_id`}),`, `,_jsx(_components.code,{children:`source_system`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Order Lines`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`sm_order_line_key`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`sm_order_key`}),`, `,_jsx(_components.code,{children:`sm_product_variant_key`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Customers`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`sm_customer_key`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`sm_store_id`}),`, `,_jsx(_components.code,{children:`source_system`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Products`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`sm_product_variant_key`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`product_id`}),`, `,_jsx(_components.code,{children:`variant_id`})]})]})]})]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Always filter by `,_jsx(_components.code,{children:`sm_store_id`}),` (SourceMedium store identifier) when working across brands or stores to avoid cross-contamination.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`best-practices`,children:`Best practices`}),`\n`,_jsx(Heading,{level:`3`,id:`filter-to-valid-orders`,children:`Filter to valid orders`}),`\n`,_jsxs(_components.p,{children:[`Always include `,_jsx(_components.code,{children:`is_order_sm_valid = TRUE`}),` to exclude test orders, cancelled orders, and other invalid transactions:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` COUNT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` valid_orders`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_orders`\"})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_order_sm_valid `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TRUE;`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`use-consistent-revenue-definitions`,children:`Use consistent revenue definitions`}),`\n`,_jsx(_components.p,{children:`Pick one and stick with it across your models:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`order_net_revenue`}),`: After discounts and refunds, excluding shipping, taxes, and shipping taxes`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`order_total_revenue`}),`: Net revenue plus net shipping, net taxes, and net shipping taxes`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`order_gross_revenue`}),`: Before discounts and refunds`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`partition-and-cluster-your-models`,children:`Partition and cluster your models`}),`\n`,_jsx(_components.p,{children:`If creating persistent tables, optimize for query performance:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`7`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:\"CREATE TABLE `your_project.your_dataset.custom_model`\"})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`PARTITION BY DATE(order_created_at)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`CLUSTER BY sm_store_id, sm_channel`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`AS (`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` SELECT ...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`2`,id:`common-patterns`,children:`Common patterns`}),`\n`,_jsx(Heading,{level:`3`,id:`customer-level-aggregations`,children:`Customer-level aggregations`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sm_customer_key,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` MIN`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(order_created_at) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` first_order_date,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` MAX`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(order_created_at) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` last_order_date,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` COUNT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`DISTINCT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sm_order_key) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` order_count,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` SUM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(order_net_revenue) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` lifetime_revenue`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_orders`\"})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_order_sm_valid `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TRUE`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`GROUP BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`channel-attribution-analysis`,children:`Channel attribution analysis`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`10`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sm_channel,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sm_sub_channel,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` COUNT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`DISTINCT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sm_order_key) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` orders,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` SUM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(order_net_revenue) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` revenue`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_orders`\"})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_order_sm_valid `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TRUE`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` AND`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` DATE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(order_created_at) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` DATE_SUB(CURRENT_DATE(), INTERVAL `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`30`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` DAY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`GROUP BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`ORDER BY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` revenue `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`DESC`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`product-affinity-what’s-bought-together`,children:`Product affinity (what’s bought together)`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`14`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`14`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` a`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`product_title`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` product_a,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` b`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`product_title`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` product_b,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` COUNT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`DISTINCT`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` a`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_order_key`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`AS`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` co_purchase_count`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_order_lines`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` a`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`JOIN`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `your_project.sm_transformed_v2.obt_order_lines`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` b`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` ON`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` a`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_order_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` b`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_order_key`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` AND`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` a`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_order_line_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` b`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`sm_order_line_key`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` a`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`is_order_sm_valid`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TRUE`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` AND`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` a`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`order_line_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` IS NOT NULL`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` -- product lines only, not the order-level row`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` AND`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` b`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`order_line_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` IS NOT NULL`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`GROUP BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`HAVING`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` co_purchase_count `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 10`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`ORDER BY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` co_purchase_count `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`DESC`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`next-steps`,children:`Next steps`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Browse available tables: `,_jsx(_components.a,{href:`/data-activation/data-tables/sm_transformed_v2/index`,children:`Data Tables Reference`})]}),`\n`,_jsxs(_components.li,{children:[`Connect your BI tool: `,_jsx(_components.a,{href:`/onboarding/analytics-tools/connect-bigquery-to-looker-studio`,children:`Connect BigQuery to Data Studio`})]}),`\n`,_jsxs(_components.li,{children:[`Learn naming conventions: `,_jsx(_components.a,{href:`/data-transformations/naming-conventions/index`,children:`Schema standards`})]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Modeling with SourceMedium","description":"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries","icon":"cubes","href":"/data-activation/managed-data-warehouse/modeling"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Before you start","slug":"before-you-start","depth":2,"children":[]},{"title":"Recommended approach","slug":"recommended-approach","depth":2,"children":[{"title":"1. Start with OBT tables","slug":"1-start-with-obt-tables","depth":3,"children":[]},{"title":"2. Join fact + dimension tables for granular needs","slug":"2-join-fact-+-dimension-tables-for-granular-needs","depth":3,"children":[]},{"title":"3. Use report tables for pre-aggregated metrics","slug":"3-use-report-tables-for-pre-aggregated-metrics","depth":3,"children":[]}]},{"title":"Common join keys","slug":"common-join-keys","depth":2,"children":[]},{"title":"Best practices","slug":"best-practices","depth":2,"children":[{"title":"Filter to valid orders","slug":"filter-to-valid-orders","depth":3,"children":[]},{"title":"Use consistent revenue definitions","slug":"use-consistent-revenue-definitions","depth":3,"children":[]},{"title":"Partition and cluster your models","slug":"partition-and-cluster-your-models","depth":3,"children":[]}]},{"title":"Common patterns","slug":"common-patterns","depth":2,"children":[{"title":"Customer-level aggregations","slug":"customer-level-aggregations","depth":3,"children":[]},{"title":"Channel attribution analysis","slug":"channel-attribution-analysis","depth":3,"children":[]},{"title":"Product affinity (what’s bought together)","slug":"product-affinity-what’s-bought-together","depth":3,"children":[]}]},{"title":"Next steps","slug":"next-steps","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"sourcemedium","siteName":"SourceMedium","title":"Modeling with SourceMedium - SourceMedium","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-22T20:22:42.191Z","originalFileLocation":"data-activation/managed-data-warehouse/modeling.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"light\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries\">\u003cmeta data-mint-head name=\"application-name\" content=\"SourceMedium\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Modeling with SourceMedium - SourceMedium\">\u003cmeta data-mint-head property=\"og:description\" content=\"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"SourceMedium\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://sourcemedium.mintlify.site/docs/_mintlify/api/og/v2?division=Get+into+BigQuery\u0026amp;title=Modeling+with+SourceMedium\u0026amp;description=How+to+build+custom+models+on+top+of+SourceMedium+tables%3A+best+practices%2C+common+patterns%2C+and+example+queries\u0026amp;theme=e85dc6896c3d34dff0291eab\u0026amp;signature=72608149be97a1877d9d20745f1bfc5dd536f9a58b7f919828a3029b4344a41e\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Modeling with SourceMedium - SourceMedium\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://sourcemedium.mintlify.site/docs/_mintlify/api/og/v2?division=Get+into+BigQuery\u0026amp;title=Modeling+with+SourceMedium\u0026amp;description=How+to+build+custom+models+on+top+of+SourceMedium+tables%3A+best+practices%2C+common+patterns%2C+and+example+queries\u0026amp;theme=e85dc6896c3d34dff0291eab\u0026amp;signature=72608149be97a1877d9d20745f1bfc5dd536f9a58b7f919828a3029b4344a41e\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/docs/mintlify-assets/_mintlify/favicons/sourcemedium/UPM2GdCpP7mp5Nu9/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"SourceMedium\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#A084FC\">\u003clink data-mint-head rel=\"canonical\" href=\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/data-activation/managed-data-warehouse/modeling.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://sourcemedium.com/#organization\",\"name\":\"SourceMedium\",\"url\":\"https://sourcemedium.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/sourcemedium/OjSPvBj0a9ize7d2/logo/light.png?fit=max\u0026auto=format\u0026n=OjSPvBj0a9ize7d2\u0026q=85\u0026s=ba06a2e9bd59b5f68b0d9a5293f04a59\"}},{\"@type\":\"WebSite\",\"@id\":\"https://sourcemedium.com/docs#website\",\"name\":\"SourceMedium\",\"url\":\"https://sourcemedium.com/docs\",\"publisher\":{\"@id\":\"https://sourcemedium.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling#webpage\",\"url\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling\",\"name\":\"Modeling with SourceMedium\",\"description\":\"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries\",\"dateModified\":\"2026-11-22T20:22:42.191Z\",\"isPartOf\":{\"@id\":\"https://sourcemedium.com/docs#website\"},\"breadcrumb\":{\"@id\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Get into BigQuery\",\"item\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Modeling with SourceMedium\",\"item\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling#article\",\"headline\":\"Modeling with SourceMedium\",\"name\":\"Modeling with SourceMedium\",\"description\":\"How to build custom models on top of SourceMedium tables: best practices, common patterns, and example queries\",\"url\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling\",\"mainEntityOfPage\":{\"@id\":\"https://sourcemedium.com/docs/data-activation/managed-data-warehouse/modeling#webpage\"},\"dateModified\":\"2026-11-22T20:22:42.191Z\",\"publisher\":{\"@id\":\"https://sourcemedium.com/#organization\"},\"isPartOf\":{\"@id\":\"https://sourcemedium.com/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"SourceMedium\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"SourceMedium\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/docs/data-activation/managed-data-warehouse/modeling.md","siteName":"SourceMedium","nav":{"global":null,"tabs":[{"tab":"Workspace","pages":[{"title":"Workspace","href":""}]},{"tab":"Connect","pages":[{"title":"Connect","href":"/data-inputs/data-inputs-overview"}]},{"tab":"How your data works","pages":[{"title":"How your data works","href":"/help-center/core-concepts/data-transformation/data-architecture"}]},{"tab":"Dashboards","pages":[{"title":"Dashboards","href":"/onboarding/analytics-tools/dashboards-and-apps"}]},{"tab":"Warehouse","groups":[{"group":"Get into BigQuery","pages":[{"title":"Warehouse","sidebarTitle":"Overview","icon":"database","href":"/data-activation/managed-data-warehouse/overview"},{"title":"Choose raw data for your warehouse","sidebarTitle":"Raw data","icon":"truck","href":"/data-activation/managed-data-warehouse/raw-data"},{"title":"Check warehouse usage","sidebarTitle":"Warehouse usage","icon":"gauge","href":"/data-activation/managed-data-warehouse/usage"},{"title":"BigQuery essentials for SourceMedium","sidebarTitle":"BigQuery essentials","description":"Practical SQL queries for analyzing your SourceMedium data in BigQuery","icon":"database","href":"/onboarding/analytics-tools/bigquery-essentials"},{"title":"Modeling with SourceMedium","icon":"cubes","href":"/data-activation/managed-data-warehouse/modeling"},{"title":"How to use metrics","sidebarTitle":"Metrics","description":"Where SourceMedium's metric definitions live, and how the same definitions power dashboards, SourceMedium Agent, and your own queries.","icon":"chart-bar","href":"/data-activation/managed-data-warehouse/metrics-and-semantic-layer"},{"title":"How do I upload a CSV file to my BigQuery instance?","sidebarTitle":"BigQuery CSV upload guide","icon":"question-mark","href":"/help-center/faq/account-management-faqs/bigquery-csv-upload-guide"}]},{"group":"SQL query library","pages":[{"title":"SQL query library","sidebarTitle":"SQL query library","icon":"code","href":"/data-activation/template-resources/sql-query-library"},{"title":"Marketing \u0026 ads","icon":"code","href":"/data-activation/template-resources/sql-query-library/marketing-and-ads"},{"title":"Messaging","icon":"code","href":"/data-activation/template-resources/sql-query-library/messaging"},{"title":"Funnel","icon":"code","href":"/data-activation/template-resources/sql-query-library/funnel"},{"title":"Journeys \u0026 lead capture","icon":"code","href":"/data-activation/template-resources/sql-query-library/journeys-and-lead-capture"},{"title":"Customers \u0026 retention","icon":"code","href":"/data-activation/template-resources/sql-query-library/customers-and-retention"},{"title":"Products","icon":"code","href":"/data-activation/template-resources/sql-query-library/products"},{"title":"Orders \u0026 revenue","icon":"code","href":"/data-activation/template-resources/sql-query-library/orders-and-revenue"},{"title":"LTV \u0026 retention","icon":"code","href":"/data-activation/template-resources/sql-query-library/ltv-and-retention"},{"title":"Attribution \u0026 data health","icon":"code","href":"/data-activation/template-resources/sql-query-library/attribution-and-data-health"},{"title":"Customer support","icon":"code","href":"/data-activation/template-resources/sql-query-library/customer-support"}]},{"group":"Common analyses (SQL)","pages":[{"title":"Cohort LTO analysis","sidebarTitle":"Cohort LTO","icon":"magnifying-glass-location","href":"/help-center/common-analyses/cohort-lto"},{"title":"Revenue retention analysis","sidebarTitle":"Revenue retention","icon":"magnifying-glass-location","href":"/help-center/common-analyses/revenue-retention"},{"title":"Understanding your gross profit","icon":"dollar-sign","href":"/help-center/common-analyses/understanding-your-gross-profit"},{"title":"Understanding your contribution margin","icon":"dollar-sign","href":"/help-center/common-analyses/understanding-your-contribution-margin"}]},{"group":"Tables","pages":[{"title":"Tables","sidebarTitle":"Tables","icon":"book","href":"/data-activation/data-tables/index"},{"group":"sm_transformed_v2","pages":[{"title":"SM Transformed v2 Tables","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/index"},{"title":"dim_customer_addresses","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_customer_addresses"},{"title":"dim_customers","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_customers"},{"title":"dim_order_discounts","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_order_discounts"},{"title":"dim_order_lines","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_order_lines"},{"title":"dim_order_shipping_lines","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_order_shipping_lines"},{"title":"dim_order_taxes","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_order_taxes"},{"title":"dim_orders","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_orders"},{"title":"dim_product_variants","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_product_variants"},{"title":"dim_stores","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_stores"},{"title":"dim_subscriptions","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_subscriptions"},{"title":"dim_subscribers","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_subscribers"},{"title":"fct_order_attribution_signals","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/fct_order_attribution_signals"},{"title":"fct_order_classification_matches","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/fct_order_classification_matches"},{"title":"fct_orders_placed","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/fct_orders_placed"},{"title":"fct_refunds_processed","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/fct_refunds_processed"},{"title":"fct_returns","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/fct_returns"},{"title":"fct_subscription_charges","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/fct_subscription_charges"},{"title":"obt_affiliate_conversions","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_affiliate_conversions"},{"title":"obt_customer_support_tickets","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_customer_support_tickets"},{"title":"obt_customer_support_ticket_messages","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_customer_support_ticket_messages"},{"title":"obt_customer_support_teams","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_customer_support_teams"},{"title":"obt_customers","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_customers"},{"title":"obt_funnel_event_history","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_funnel_event_history"},{"title":"obt_inventory_positions","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_inventory_positions"},{"title":"obt_media_mix_performance","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_media_mix_performance"},{"title":"obt_order_lines","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_order_lines"},{"title":"obt_orders","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_orders"},{"title":"obt_reviews","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_reviews"},{"title":"obt_subscriptions","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_subscriptions"},{"title":"obt_subscription_charges","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/obt_subscription_charges"},{"title":"rpt_ad_creative_assets","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_ad_creative_assets"},{"title":"rpt_ad_performance_daily","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_ad_performance_daily"},{"title":"rpt_cohort_ltv_by_first_valid_purchase_attribute_no_product_filters","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_cohort_ltv_by_first_valid_purchase_attribute_no_product_filters"},{"title":"rpt_executive_summary_daily","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_executive_summary_daily"},{"title":"rpt_funnel_events_performance_hourly","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_funnel_events_performance_hourly"},{"title":"rpt_media_mix_channel_daily","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_media_mix_channel_daily"},{"title":"dim_outbound_messages","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/dim_outbound_messages"},{"title":"rpt_outbound_message_performance_daily","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_outbound_message_performance_daily"},{"title":"rpt_subscription_signup_cohort_retention","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_subscription_signup_cohort_retention"},{"title":"rpt_subscriptions_performance_daily","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_subscriptions_performance_daily"},{"group":"Planned","pages":[{"title":"rpt_order_attributed_marketing_utms","icon":"table","href":"/data-activation/data-tables/sm_transformed_v2/rpt_order_attributed_marketing_utms"}]}]},{"group":"sm_views","pages":[{"title":"SM Views","icon":"table","href":"/data-activation/data-tables/sm_views/index"},{"title":"rpt_customers_first_and_last_order_summary_v1","icon":"table","href":"/data-activation/data-tables/sm_views/rpt_customers_first_and_last_order_summary_v1"},{"title":"rpt_order_returns_v1","icon":"table","href":"/data-activation/data-tables/sm_views/rpt_order_returns_v1"}]},{"group":"Metadata tables","pages":[{"title":"dim_data_dictionary","icon":"table","href":"/data-activation/data-tables/sm_metadata/dim_data_dictionary"},{"title":"dim_semantic_metric_catalog","icon":"book-open","href":"/data-activation/data-tables/sm_metadata/dim_semantic_metric_catalog"}]},{"group":"Experimental tables","pages":[{"title":"SM Experimental Tables","icon":"flask","href":"/data-activation/data-tables/sm_experimental/index"},{"title":"rpt_ad_attribution_performance_daily","icon":"table","href":"/data-activation/data-tables/sm_experimental/rpt_ad_attribution_performance_daily"},{"title":"obt_purchase_journeys_with_mta_models","icon":"table","href":"/data-activation/data-tables/sm_experimental/obt_purchase_journeys_with_mta_models"}]}]},{"group":"Schema standards","pages":[{"title":"Schema standards","icon":"tags","href":"/data-transformations/naming-conventions/index"}]}]},{"tab":"Multi-Touch Attribution","pages":[{"title":"Multi-Touch Attribution","href":"/mta/mta-overview"}]},{"tab":"AI Agents","pages":[{"title":"AI Agents","href":"/ai-analyst"}]},{"tab":"Help","pages":[{"title":"Help","href":"/faq"}]}]},"basePath":"","title":"Modeling with SourceMedium - SourceMedium","deploymentId":"dpl_5rhUmeYihYWreyVvacFyguXMfbnu","buildId":"dpl_5rhUmeYihYWreyVvacFyguXMfbnu","dynamics":[],"chunks":[]}