Make A Macro Worth Having
Extract repeated SQL into a dbt macro only when it improves consistency and reviewability.
Four staging models convert cents to dollars with slightly different casts and rounding. A macro is justified when repeated logic has one business meaning and a stable interface. The shortcut is to patch the final mart because it is the visible failure. That hides whether the defect is raw data, staging cleanup, join grain, or metric definition. Find repetition with meaning Compare the four expressions and confirm they all mean monetary cents to decimal dollars. Do not abstract code that only looks similar but means different things. Write small macro Create cents_to_dollars(column_name, scale=2) and quote the string argument in calls.…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in