Skip to content

Convert ROAS values to percentages for better readability#36

Open
MikaKerman wants to merge 17 commits intomasterfrom
real-time-orders
Open

Convert ROAS values to percentages for better readability#36
MikaKerman wants to merge 17 commits intomasterfrom
real-time-orders

Conversation

@MikaKerman
Copy link
Contributor

@MikaKerman MikaKerman commented Jul 6, 2025

Summary

Updated the cpa_and_roas model to display ROAS (Return on Advertising Spend) values as percentages instead of ratios for improved business readability.

Changes Made

  • Modified the return_on_advertising_spend column calculation in jaffle_shop_online/models/marketing/cpa_and_roas.sql
  • Changed formula from 1.0 * attribution_revenue / total_spend to 100.0 * attribution_revenue / total_spend
  • Updated code comments to reflect the percentage format

Impact

  • Before: ROAS values ranged from 0.001 to 19.596 (difficult to interpret)
  • After: ROAS values now range from 0.1% to 1959.6% (much more intuitive)
  • Business value: Marketing teams can now easily understand campaign performance at a glance
    • Values < 100% = losing money
    • Values > 100% = profitable campaigns
    • Values > 200% = strong performance (2x return)

Example

  • Facebook campaign on May 4th:
    • Before: 19.596 ROAS
    • After: 1959.6% ROAS ✨

This change makes the data much more business-friendly and easier for stakeholders to interpret.

Summary by CodeRabbit

  • Enhancements
    • ROAS (Return on Advertising Spend) is now displayed as a percentage instead of a unitless ratio.

- 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
@coderabbitai
Copy link

coderabbitai bot commented Jul 6, 2025

Walkthrough

The 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

File(s) Change Summary
jaffle_shop_online/models/marketing/cpa_and_roas.sql Modified ROAS calculation to output a percentage instead of a unitless ratio.

Possibly related PRs

  • Revert "Renew cpa and roas" #25: Reverts a previous refactor of the CPA and ROAS SQL model, affecting the same metrics and model as this PR.
  • Renew cpa and roas #21: Reorganizes the cpa_and_roas model logic and changes aggregation/filtering, related through modifications to the same model.

Poem

🥕
In the land of data, where queries play,
ROAS now shines as percent today!
No more plain ratios, just numbers that gleam,
Multiplying by 100, a marketer’s dream.
Crunching the carrots, reporting with glee—
The rabbit approves, as happy as can be!
🥕


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
jaffle_shop_online/models/marketing/cpa_and_roas.sql (1)

75-75: Optional: round for human-friendly output

If 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).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a11273 and 77c48d0.

📒 Files selected for processing (1)
  • jaffle_shop_online/models/marketing/cpa_and_roas.sql (1 hunks)

Comment on lines +72 to 76
-- 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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_pct

Run 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.

MikaKerman and others added 16 commits August 10, 2025 18:28
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments