Switchboard Docs
ReferenceSource Models

Google Sheets Models

Copy-paste SQL model for turning a Google Sheets SKU COGS ledger into a clean, versioned table.

google_sheets_sku_cogs_ledger

with 
	base as (
		select 
		  sku 
		  , _row 
		  , product_unit_cost :: decimal as product_unit_cost
		  , shipping_cost :: decimal as shipping_cost
		  , other_costs :: decimal as other_cost
		  , coalesce(start_date, '2023-01-01'::date) :: date as start_date
		  , coalesce(end_date, current_date) :: date as end_date
		  , note
		  , md5(sku::varchar || _row::varchar) as id
		  
		from {{sources.gsheet.gsheet}}
		
		where sku::varchar is not null
		  )
		
	select 
	  * 
	  , row_number() over (partition by sku, (start_date::varchar||end_date::varchar) order by _row desc) as index
	from base 

On this page