Or via Elementary: Fix ROAS metric: Convert historical_orders from cents to dollars - #988
Open
elementary-data-demo[bot] wants to merge 1 commit into
Open
Or via Elementary: Fix ROAS metric: Convert historical_orders from cents to dollars#988elementary-data-demo[bot] wants to merge 1 commit into
elementary-data-demo[bot] wants to merge 1 commit into
Conversation
The orders model unions historical_orders (amounts in cents) with real_time_orders (amounts in dollars), creating a unit mismatch that corrupts downstream calculations. Apply the cents_to_dollars macro to all monetary fields in historical_orders, matching the conversion in real_time_orders. This ensures both sources produce values in the same unit (AUD). Fixes: - Corrupted RETURN_ON_ADVERTISING_SPEND metric (dropped 65.166 → 0.145) - 11 consecutive column anomaly test failures on cpa_and_roas - Downstream revenue-attribution calculations in dashboards"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
ordersmodel unites two sources with incompatible units:historical_orders: stores amounts in cents (e.g., 10000 cents = $100)real_time_orders: stores amounts in dollars (e.g., 100 = $100)This unit mismatch corrupts the
RETURN_ON_ADVERTISING_SPENDmetric incpa_and_roas, which calculates:attribution_revenue / total_spend. When real-time orders (100× smaller in raw values) mix with historical data, ROAS becomes drastically inaccurate.Observed Impact: Average ROAS dropped from 65.166 to 0.145 as the proportion of real-time orders increased.
Solution
Apply the
cents_to_dollarsmacro to all monetary fields inhistorical_orders.sql, ensuring both historical and real-time orders return values in dollars (AUD).Changes
cents_to_dollars()macro for all amount columnsTesting
After merge:
Related Issues
cpa_and_roas.RETURN_ON_ADVERTISING_SPEND(11 failures since June 8)Created by:
mika+demo@elementary-data.com