Convert ROAS values to percentages for better readability#36
Convert ROAS values to percentages for better readability#36MikaKerman wants to merge 17 commits intomasterfrom
Conversation
- Modified return_on_advertising_spend column to show percentages instead of ratios - Updated calculation from 1.0 * revenue/spend to 100.0 * revenue/spend - Makes ROAS values more intuitive (e.g., 200% instead of 2.0) - Range is now 0.1% to 1959.6% instead of 0.001 to 19.596
WalkthroughThe ROAS (Return on Advertising Spend) calculation in the CPA and ROAS SQL model was updated to display the result as a percentage by multiplying the ratio by 100. The underlying logic and conditions for calculating ROAS and CPA remain unchanged. Changes
Possibly related PRs
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
jaffle_shop_online/models/marketing/cpa_and_roas.sql (1)
75-75: Optional: round for human-friendly outputIf this column is surfaced directly to business users, the raw float can be noisy (e.g.
1959.643557892).
Rounding inside the model keeps every downstream consumer consistent:- then 100.0 * attr_agg.attribution_revenue / spend_agg.total_spend + then round(100.0 * attr_agg.attribution_revenue / spend_agg.total_spend, 2)Feel free to adjust precision (2 dp is common for percentages).
| -- ROAS as percentage: multiply by 100 to show as percentage | ||
| case | ||
| when coalesce(spend_agg.total_spend, 0) > 0 and coalesce(attr_agg.attribution_revenue, 0) > 0 | ||
| then 1.0 * attr_agg.attribution_revenue / spend_agg.total_spend | ||
| then 100.0 * attr_agg.attribution_revenue / spend_agg.total_spend | ||
| else null |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Clarify the unit in the column name to prevent downstream mis-interpretation
return_on_advertising_spend used to be a ratio (0–∞).
After multiplying by 100 it is now a percentage (0–∞ %), yet the column name stayed the same.
Any dashboards or tests that still assume “1 = break-even” will silently mis-read “100 = break-even”.
Consider renaming the field (e.g. return_on_advertising_spend_pct) or, at minimum, updating all documentation / metadata so that consumers know the new unit.
- end as return_on_advertising_spend
+ end as return_on_advertising_spend_pctRun the following to surface all usages that may need an update:
🏁 Script executed:
#!/bin/bash
# Find every reference to the old column name
rg -n "return_on_advertising_spend\b"Length of output: 1001
Rename return_on_advertising_spend to return_on_advertising_spend_pct across the project
Since the metric is now expressed as a percentage, we need to update every reference to avoid downstream confusion:
• jaffle_shop_online/models/marketing/cpa_and_roas.sql (line 77):
- end as return_on_advertising_spend
+ end as return_on_advertising_spend_pct• jaffle_shop_online/models/marketing/schema.yml (line 151):
- - name: return_on_advertising_spend
+ - name: return_on_advertising_spend_pct• data_creation/data_injection/inject_jaffle_shop_exposures.py (multiple places): update all occurrences of
name="return_on_advertising_spend"
target_name="return_on_advertising_spend"
Column(..., name="return_on_advertising_spend")to use return_on_advertising_spend_pct.
Also review any dashboards, tests, or docs that consume this field to ensure they reflect the new unit.
🤖 Prompt for AI Agents
In jaffle_shop_online/models/marketing/cpa_and_roas.sql around line 77, rename
the field alias from return_on_advertising_spend to
return_on_advertising_spend_pct to reflect the percentage unit. Then, update
jaffle_shop_online/models/marketing/schema.yml around line 151 to rename the
corresponding field to return_on_advertising_spend_pct. In
data_creation/data_injection/inject_jaffle_shop_exposures.py, find and replace
all occurrences of return_on_advertising_spend with
return_on_advertising_spend_pct in name, target_name, and Column definitions.
Finally, review and update any dashboards, tests, or documentation that
reference this field to use the new name and unit consistently.
- Updated ads_data_generator.py to improve ad data generation with detailed documentation and realistic spend patterns across platforms. - Refactored session_data_generator.py to include ad attribution linkage, ensuring sessions reference actual ad campaigns for accurate marketing analysis. - Enhanced training_data_generator.py and validation_data_generator.py to maintain consistent data relationships and realistic customer behavior patterns. - Added logging for time ranges in data generation processes to facilitate monitoring and debugging.
…models - Updated the date filtering logic to include a 2-day interval for both historical_orders.sql and real_time_orders.sql. - This change ensures that the queries capture orders from the last two days, improving the accuracy of the data retrieved.
- Updated sources.yml to include dynamic database reference for ads and sessions sources. - This change allows for better adaptability to different environments by utilizing the target database configuration.
…tead of started_at - Changed the date selection in the attribution_aggregated query to utilize attr.converted_at for improved accuracy in marketing analysis.
- Changed unique_key in agg_sessions.sql to include both session_id and platform for better session tracking. - Modified marketing_ads.sql to switch materialization from incremental to table, optimizing data retrieval and processing.
- Adjusted anomaly_sensitivity from 2 to 1.5 for more precise anomaly detection. - Extended training_period count from 14 to 30 days to enhance model training accuracy.
… instructions - Introduced run_pipeline.sh to automate the entire data pipeline process, including data generation, model building, and testing. - Updated README.md with a new section detailing the quick start instructions for running the complete pipeline, including expected results for anomaly detection.
- Updated the import statement for DbtRunner to use CommandLineDbtRunner for improved compatibility with command line operations.
- Updated import statements for DbtRunner to use CommandLineDbtRunner in multiple files for improved compatibility with command line operations. - This change enhances consistency and maintainability across the data generation and injection modules.
…on and injection scripts - Updated import statements in multiple files to replace CommandLineDbtRunner with SubprocessDbtRunner for improved compatibility and consistency. - This change enhances maintainability across the data generation and injection modules.
- Removed the hardcoded "training" and "validation" parameters from the generate_sessions_data function calls to streamline the session data generation process. - This change enhances flexibility and simplifies the function usage across the incremental data creation workflow.
- Introduced a step to initialize Elementary metadata before injecting tests, ensuring that metadata tables are populated. - Added a DbtRunner instance to run Elementary models, enhancing the test injection process by collecting necessary metadata about existing models.
- Add detailed debug output to get_model_ids() and get_model_id_from_name() - Show all available models grouped by package - Display exact query results and failure reasons - Add Elementary metadata initialization before test injection - This will help diagnose why stg_orders lookup fails in CI
…p-abc789-143022 Joost Boonzajer Flaes via Elementary: Convert individual ownership to team-based ownership across all models
Introduces three types of intentional data quality issues for testing and demonstration purposes: - Invalid order status: Occasionally generates "cancelled" status (not in accepted values) - Duplicate payment IDs: Randomly skips payment_id increment to create duplicates - Duplicate customer emails: Reuses emails to test uniqueness constraints Each failure is clearly documented with comments explaining the intentional nature and which specific dbt tests will fail. This allows demonstration of data quality testing and test failure scenarios without breaking the data generation pipeline. Affected tests: - accepted_values_stg_orders_status - unique_stg_payments_payment_id - unique_stg_signups_customer_email - unique_customers_customer_email Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
Updated the
cpa_and_roasmodel to display ROAS (Return on Advertising Spend) values as percentages instead of ratios for improved business readability.Changes Made
return_on_advertising_spendcolumn calculation injaffle_shop_online/models/marketing/cpa_and_roas.sql1.0 * attribution_revenue / total_spendto100.0 * attribution_revenue / total_spendImpact
Example
This change makes the data much more business-friendly and easier for stakeholders to interpret.
Summary by CodeRabbit