DEV Community

M Maaz Ul Haq for DataSort

Posted on Originally published at datasort.app

Blending Shopify and Klaviyo Data: Reconciling E-Commerce Attribution Without DAX

Every Monday, hundreds of e-commerce teams sit down to answer a deceptively simple question: how much real, net revenue did last week's email campaigns generate? On paper, this should take thirty seconds. In practice, Shopify and Klaviyo report two different realities.

Klaviyo claims attribution on revenue that Shopify later flags as canceled or refunded. Timezones between the two platforms rarely match by default. Currency values arrive formatted with symbols and trailing spaces in one export, while order IDs contain prefixes like #1001 in Shopify and raw numeric strings in Klaviyo event logs. To get an honest picture of customer acquisition cost and flow performance, you have to merge both datasets.

The Power BI Trap: Why DAX Fails Lean Teams

When spreadsheets start breaking, standard enterprise advice is to move to Microsoft Power BI. You import your exports, open the data model, and immediately hit a wall known as DAX (Data Analysis Expressions).

In Power BI, calculating net attributed revenue across mismatched date tables and relationship keys requires complex measures. If your relationships are many-to-many, Power BI demands context transition formulas, custom bridge tables, and inactive relationship workarounds.

Attributed_Net_Revenue = 
CALCULATE(
    SUM(ShopifyOrders[TotalSales]) - SUM(ShopifyOrders[Refunds]),
    USERELATIONSHIP(ShopifyOrders[Email], KlaviyoEvents[CustomerEmail]),
    TREATAS(VALUES(KlaviyoEvents[CampaignID]), ShopifyOrders[CampaignRef]),
    FILTER(ShopifyOrders, ShopifyOrders[FinancialStatus] = "paid")
)
Enter fullscreen mode Exit fullscreen mode

If someone misconfigures a date table or imports a customer email with trailing whitespace, the entire card displays blank or produces circular dependency errors.

The Real Problem: The Messy Middle Layer

Most reporting guides skip over what happens before data lands in a visualization tool. Generic BI platforms such as Metabase, Looker Studio, or Superset assume your data already lives in a clean, unified SQL warehouse. Small direct-to-consumer brands rarely have that infrastructure. Instead, they work with raw CSV and Excel downloads pulled directly from admin exports.

Here are the exact friction points that break standard tools when blending these two exports:

  • Header Inconsistencies: Shopify exports customer emails under Email, while Klaviyo lists them under Recipient Email or Email Address.
  • Timestamp Offsets: Shopify often defaults to the store's local timezone (like EST), while Klaviyo event feeds export in UTC, resulting in orders falling on different days.
  • Duplicate Attributions: Klaviyo logs multiple interactions per recipient (opens, clicks, SMS sent), which inflates row counts if you attempt a naive Excel lookup against single Shopify orders.
  • Dirty Text Fields: Accidental spaces, inconsistent capitalization in discount codes, and unescaped commas inside address columns corrupt column parsing.

Step-by-Step: Data Cleaning and Joining

Step 1: Sanitize and Standardize Exports

Before merging, clean raw text columns:

  • Strip leading and trailing whitespace from strings.
  • Coerce email addresses to standard lowercase.
  • Reconcile timezone differences by casting timestamps to UTC before grouping by day.
  • Deduplicate event logs so that single purchases are not double-counted across multiple campaign interactions.

Step 2: Combine Orders and Marketing Events

Once both datasets share uniform fields, join them using common keys (such as email and timestamp windows). If working in Python, this can be handled via pandas:

import pandas as pd

shopify = pd.read_csv('shopify_orders.csv')
klaviyo = pd.read_csv('klaviyo_events.csv')

# Standardize keys
shopify['email'] = shopify['Email'].str.strip().str.lower()
klaviyo['email'] = klaviyo['Recipient Email'].str.strip().str.lower()

# Deduplicate marketing clicks
klaviyo_unique = klaviyo.drop_duplicates(subset=['email', 'Campaign Name'])

# Merge on key
merged = pd.merge(shopify, klaviyo_unique, on='email', how='inner')
Enter fullscreen mode Exit fullscreen mode

Step 3: Compute Net Revenue

Account for refunds and chargebacks directly:

paid_orders = merged[merged['Financial Status'] == 'paid']
net_revenue = paid_orders['Total Sales'].sum() - paid_orders['Refunds'].sum()
print(f"Net Attributed Revenue: ${net_revenue:,.2f}")
Enter fullscreen mode Exit fullscreen mode

Conclusion

Instead of struggling with DAX relationship modeling, addressing data hygiene at the ingestion stage provides clean, reliable attribution figures without maintaining an enterprise BI infrastructure.

Top comments (0)