Skip to main content

When to use this

Raw data often contains rows that shouldn’t make it into your analytics — test records, incomplete entries, or data that violates business rules. Rather than letting bad data silently corrupt dashboards and reports, filter it out (or flag it) during the transformation step. Common scenarios include:
  • Removing test or sandbox records (e.g., emails ending in @test.com)
  • Excluding rows with missing required fields
  • Filtering out records outside a valid date range
  • Flagging anomalous values for review

Sample input

An orders table in the Raw layer with some invalid records: We want to keep only rows where: the email is not a test address, the amount is positive, and the email is not NULL.

Implementation

Apply the same WHERE filters. BigQuery’s REGEXP_CONTAINS can be useful for more complex patterns.
For more complex email validation, use regex:

Expected output

Rows 1002 (test email), 1003 (negative amount), and 1004 (NULL email) are excluded.

Tips and gotchas

Filtering is destructive — once rows are removed, they won’t appear in downstream tables. If you’re unsure whether certain records should be excluded, consider flagging them with a boolean column (is_valid) instead of removing them. This lets analysts make the final call.
Keep your validation rules documented and versioned. When business rules change (e.g., a new test domain gets added), you’ll want to update the filter in one place rather than hunting for hardcoded values across multiple transformations.