New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
None of the four built-in tests catches a completed order with a negative total. Finance just found one.
What you'll have at the end
A custom dbt test that fails the build the moment a completed order's total goes negative
You need
A dbt project with a fact model that has a status column and more than one numeric amount column, plus a target you can run dbt test against without touching production.
Not covered
Deciding whether a check like this belongs in your own project or in a shared, ready-made test package your whole team pulls in.
Leans on
Turn repeated SQL into a dbt macro
for the general mechanics of writing and debugging a macro, if the {{ }} templating in the generic test is unfamiliar.
Catch a broken foreign key with dbt's relationships test
for starting a new test at a gentler severity and promoting it later, if you'd rather roll this out gradually than fix the known bad rows first.
Checked 25 Aug 2026
Part of the dbt (Data Build Tool) cookbook