Clearing 2026: why UK universities need recruitment intelligence
UK universities face a deficit crisis. Student Recruitment Intelligence can transform Clearing from chaos to precision.

BigQuery offers powerful scripting capabilities that can simplify complex workflows. In this post, we’ll explore two essential techniques: using IF...THEN...END IF for procedural control and leveraging the metadata in project.dataset.__TABLES__ to ensure your Google Analytics 4 (GA4) data is ready before running queries. These strategies help you avoid unnecessary processing, reduce costs, and improve efficiency in your data pipelines.
While many SQL developers rely on the CASE WHEN expression for conditional logic within a SELECT statement, BigQuery’s scripting environment allows for more dynamic control with IF...THEN...END IF. This control-flow statement is especially useful in stored procedures and scripts where you need to:
The following example demonstrates how to execute a block of code only on weekdays:
DECLARE current_day STRING;
BEGIN
-- Get today's day of the week
SET current_day = FORMAT_TIMESTAMP('%A', CURRENT_TIMESTAMP());
-- Only run the query if it's a weekday
IF current_day NOT IN ('Saturday', 'Sunday') THEN
SELECT 'Running weekday report...' AS status;
ELSE
SELECT 'Skipping execution. It is the weekend.' AS status;
END IF;
END;
Benefits of Using IF...THEN...END IF:
CASE WHEN, this syntax allows for multi-step procedural operations.When working with GA4 exports in BigQuery, timing is critical. GA4 tables (like events_YYYYMMDD) may not arrive at a predictable time each day, and rerunning the same transformation repeatedly is not only inefficient but can also lead to duplicate processing.
BigQuery provides a system view (project.dataset.__TABLES__) that contains metadata for each table, including the last_modified_time. By querying this view, you can determine whether a table has been updated recently and decide if your processing should run.
Before running your main query, check if the destination table has already been refreshed:
We build intelligence platforms on BigQuery, Dataform and Google Cloud — from setup to ongoing optimisation.
DECLARE alreadyRanToday BOOL;SET alreadyRanToday = ( SELECT COUNT(*) > 0 FROM `project.dataset.__TABLES__` WHERE table_id = 'table_you_are_creating' AND DATE(TIMESTAMP_MILLIS(last_modified_time)) = DATE(CURRENT_DATE()));Next, ensure that yesterday’s GA4 table exists and was modified recently. This step protects against processing incomplete or missing data.
DECLARE ga4TableExist BOOL;SET ga4TableExist = ( SELECT COUNT(*) > 0 FROM `project.dataset.__TABLES__` WHERE table_id = CONCAT('events_', FORMAT_DATE('%Y%m%d', DATE_SUB(DATE(CURRENT_DATE()), INTERVAL 1 DAY))) AND TIMESTAMP_DIFF( TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 60 MINUTE), TIMESTAMP_ADD(TIMESTAMP_MILLIS(last_modified_time), INTERVAL 60 MINUTE), MINUTE ) > 10);Finally, combine these checks to run your query only when both conditions are met:
IF NOT alreadyRanToday THEN IF ga4TableExist THEN SELECT * FROM `project.dataset.events_*` WHERE _TABLE_SUFFIX = DATE_SUB(DATE(CURRENT_DATE()), INTERVAL 1 DAY); END IF;END IF;Key Advantages:
project.dataset.__TABLES__ for metadata queriesThe project.dataset.__TABLES__ view is an invaluable resource for managing your BigQuery workflows. Here’s why:
table_id and last_modified_time.For other types of information_schema that are available in BigQuery, you can have a look at this google documentation.
Combining the procedural flexibility of IF...THEN...END IF with the strategic use of metadata from project.dataset.__TABLES__ provides a robust framework for automating BigQuery workflows. This approach not only streamlines your operations but also ensures data accuracy and cost efficiency.
By integrating these advanced techniques, you can optimise your data pipelines and stay ahead in your data processing tasks. Let's discuss!
We build intelligence platforms on BigQuery, Dataform and Google Cloud — from setup to ongoing optimisation.
Take our short assessment to find out where your data stack stands and what to prioritise next.
UK universities face a deficit crisis. Student Recruitment Intelligence can transform Clearing from chaos to precision.
Dara and Matthew recap 2025 with 12 top highlights, AI, analytics, and the best moments on The Measure Pod.
AI expert Daniel Hulme, founder of Satalia, shares his journey from UCL PhD to entrepreneur, discussing AI, consciousness & deep tech.