Skip to content

Maayan via Elementary: Fix: Convert historical_orders monetary amounts from cents to dollars#905

Open
joostboon wants to merge 1 commit intomasterfrom
elementary-fix-historical-orders-cents-to-dollars-839271
Open

Maayan via Elementary: Fix: Convert historical_orders monetary amounts from cents to dollars#905
joostboon wants to merge 1 commit intomasterfrom
elementary-fix-historical-orders-cents-to-dollars-839271

Conversation

@joostboon
Copy link
Copy Markdown
Collaborator

Problem

The historical_orders model was exposing monetary amounts in cents while real_time_orders already converts them to dollars using the cents_to_dollars() macro. Since both models are combined via UNION ALL in the orders model, this unit mismatch caused:

  • ~100× inflation in revenue for historical orders
  • Propagation through customer_conversionsattribution_touchescpa_and_roas
  • Persistent anomaly detection failures on the RETURN_ON_ADVERTISING_SPEND column (74 failure events since Oct 2025)

Fix

  • historical_orders.sql: Apply cents_to_dollars() macro to all monetary columns (amount, credit_card_amount, coupon_amount, bank_transfer_amount, gift_card_amount)
  • real_time_orders.sql: Added clarifying comment (no logic changes)

Impact

This resolves incident 2924da99-a790-4dcb-b92a-5f9571d1fdce (HIGH severity, ACKNOWLEDGED) on the critical cpa_and_roas model owned by @Finance-team.

Created by: maayan+172@elementary-data.com

historical_orders.amount was stored in cents while real_time_orders.amount
was already in dollars. Since both models are UNIONed in the orders model,
this caused a ~100x inflation in revenue for historical data, which
propagated through customer_conversions → attribution_touches → cpa_and_roas,
triggering the ROAS anomaly detection test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant