Exporting a quarterly product similarity analysis to Google Sheets
This use case illustrates a concrete use of the Biron plugin in Zapier. If you are not yet familiar with how it works (authentication, query structure, variable management), please read the Biron × Zapier guide first before continuing.
What we’re building
Section titled “What we’re building”A Zap that triggers every quarter, runs a product similarity analysis on the past quarter, and automatically populates a Google Sheet with the results.
The goal: identify product pairs purchased together more often than chance — to improve product recommendations or build bundle offers.
Zap architecture
Section titled “Zap architecture”Schedule → Date calculation → Product similarity query → Google SheetsTrigger — Schedule by Zapier
Section titled “Trigger — Schedule by Zapier”Configure a Schedule by Zapier block:
- Frequency: Custom Frequency
- Frequency Type: Monthly
- Interval: 3
Date calculation
Section titled “Date calculation”Biron queries require explicit dates. This block dynamically generates the boundaries of the previous quarter on each run.
Add a Code by Zapier block (Python). Use the following prompt to generate the code, then paste the result into the block:
Role: Python expert for Zapier.Goal: Create a relative date calculation script.
Calculate the following dates, handling calendar edge cases(leap years, end of month):- Yesterday- Start of previous quarter
Output: return an "output" dictionary with all dates in YYYY-MM-DD format.Product similarity query
Section titled “Product similarity query”This step runs a product similarity analysis in NexusQL. It identifies the SKU pairs most frequently purchased together during the past quarter and calculates their Lift.
Unlike other use cases, the NexusQL query here is not generated from a Biron chart — it is built manually using your SQL knowledge, assisted by an LLM. Once the query is ready, paste it into the Biron Query block in Zapier and replace the static dates with the variables produced in the previous step.
-- ============================================================-- ANALYSE DE CO-ACHAT PRODUITS — Market Basket Analysis-- Période : 2024-01-01 → 2025-03-17---- Objectif : identifier les paires de produits fréquemment-- achetées ensemble et mesurer la force de leur association-- via le lift.---- Lift = (P(A∩B)) / (P(A) × P(B))-- = co_achats(A,B) × total_commandes / (commandes(A) × commandes(B))-- Lift > 1 → association positive (au-delà du hasard)-- Lift = 1 → indépendance-- Lift < 1 → association négative-- ============================================================
SELECT t1.product_1, t1.product_2, t1.co_achats AS n_orders_A_B, -- Nb commandes contenant A et B t2.transaction AS n_orders_A, -- Nb commandes contenant A t3.transaction AS n_orders_B, -- Nb commandes contenant B t4.transaction AS n_orders_total, -- Nb total de commandes n_orders_A_B / n_orders_A / n_orders_B * n_orders_total AS lift, -- Force de l'association (> 1 = affinité réelle), n_orders_A_B / n_orders_total AS support_A_B, n_orders_A / n_orders_total AS support_A, n_orders_B / n_orders_total AS support_B
FROM
-- -------------------------------------------------------- -- BLOC 1 : Paires de produits co-achetés (self-join) -- Chaque commande est jointe avec elle-même pour générer -- toutes les combinaisons de produits possibles. -- La condition t1.product < t2.product garantit que chaque -- paire (A, B) n'apparaît qu'une fois (évite (A,B) et (B,A)) -- -------------------------------------------------------- ( SELECT t1.product AS product_1, t2.product AS product_2, COUNT( ) AS co_achats FROM ( SELECT DIMENSION( 'order_id' ) AS order_id, DIMENSION( 'product_name' ) AS product, METRIC( 'transactions_order_date.billing_n_orders' ) AS trasaction FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2025-03-17' AND product != 'na' -- exclut les lignes sans produit identifié GROUP BY order_id, product ) AS t1
LEFT JOIN ( SELECT DIMENSION( 'order_id' ) AS order_id, DIMENSION( 'product_name' ) AS product, METRIC( 'transactions_order_date.billing_n_orders' ) AS trasaction FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2025-03-17' AND product != 'na' GROUP BY order_id, product ) AS t2 ON t1.order_id = t2.order_id
WHERE t1.product < t2.product -- déduplique les paires (A,B) sans DISTINCT GROUP BY t1.product, t2.product ) AS t1 -- -------------------------------------------------------- -- BLOC 2 : Fréquence individuelle de product_1 -- Utilisé pour calculer P(A) dans la formule du lift -- -------------------------------------------------------- LEFT JOIN ( SELECT DIMENSION( 'product_name' ) AS product, METRIC( 'transactions_order_date.billing_n_orders' ) AS transaction FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2025-03-17' AND product != 'na' GROUP BY product ) AS t2 ON t1.product_1 = t2.product -- -------------------------------------------------------- -- BLOC 3 : Fréquence individuelle de product_2 -- Utilisé pour calculer P(B) dans la formule du lift -- Identique au bloc 2, jointure sur product_2 -- -------------------------------------------------------- LEFT JOIN ( SELECT DIMENSION( 'product_name' ) AS product, METRIC( 'transactions_order_date.billing_n_orders' ) AS transaction FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2025-03-17' AND product != 'na' GROUP BY product ) AS t3 ON t1.product_2 = t3.product -- -------------------------------------------------------- -- BLOC 4 : Volume total de commandes (scalaire) -- CROSS JOIN car c'est une valeur unique à propager -- sur toutes les lignes — dénominateur commun du lift -- -------------------------------------------------------- CROSS JOIN ( SELECT METRIC( 'transactions_order_date.billing_n_orders' ) AS transaction FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2025-03-17' AND DIMENSION( 'product_name' ) != 'na' ) AS t4
-- ---------------------------------------------------------- FILTER: minimum support threshold at 10%-- Eliminates anecdotal associations that would inflate-- the lift for very rarely purchased products.-- Adjust as needed (0.01 = 1%, 0.001 = 0.1%)-- ---------------------------------------------------------WHERE support_A_B > 0.01 AND support_A > 0.01 AND support_B > 0.01
ORDER BY n_orders_A_B DESCThe returned data covers:
| Column | Description |
|---|---|
| Product A | First SKU in the pair |
| Product B | Second SKU in the pair |
| Lift | Association score between the two products |
| Shared orders | Number of orders containing both products |
Populate — Google Sheets
Section titled “Populate — Google Sheets”Before configuring the Zapier block, prepare your file:
- Create a new Google Sheet in your Drive
- On the first row, enter the column headers:
Product A,Product B,Lift,Shared Orders
Then add a Create Multiple Spreadsheet Rows block in Zapier and configure:
- Spreadsheet: select the file created above
- Worksheet: the target sheet
- Columns: map each column to the corresponding fields from the Biron query
Expected result
Section titled “Expected result”Every quarter, your Google Sheet is automatically populated with the most associated product pairs over the past period. You have a ready-to-use dataset to feed your merchandising decisions, product recommendations, or bundle construction.