Preparing and using data for analysis · Topic 1 of 3

Preparing Data for Visualization and BI

Connect Looker and Looker Studio to BigQuery, precalculate fields, use BI Engine and materialized views, fix slow queries, secure with masking and DLP.

  • 5 min
In a nutshell
  • Looker for a governed semantic layer; Looker Studio for quick dashboards; Connected Sheets for spreadsheet users.
  • Precalculate with aggregate tables, materialized views or Looker persistent derived tables.
  • BI Engine adds in-memory acceleration; materialized views refresh incrementally.

What it is

Dashboards need answers in seconds, from data that each viewer is allowed to see. Preparing data for visualization means connecting the right tool, precalculating expensive work, using BigQuery's BI acceleration features, fixing slow queries and applying security and masking before the first chart is drawn.

Curated tablesPrecalculateaggregates, MVsAccelerateBI EngineSecuremasking, rowsBI toolLooker, Looker Studio

How it works

Connecting to tools

ToolFits
LookerGoverned semantic layer in LookML: one definition of each metric, reused across reports
Looker StudioQuick, shareable dashboards with a native BigQuery connector
Connected SheetsSpreadsheet users analysing BigQuery data from Google Sheets without exporting it
Third-party BI toolsJDBC and ODBC drivers for BigQuery

In Looker Studio, a data source uses either the owner's credentials (viewers see what the owner can see) or the viewer's credentials (each viewer's own BigQuery permissions apply). Row-level security only filters per viewer when the viewer's credentials are used.

Precalculating fields

Calculate once, read many times.

TechniqueUse it for
Derived columns at load timeFixed calculations such as net price or fiscal period
Aggregate tables built by a scheduled query or DataformDaily or monthly summaries feeding dashboards
Materialized viewsAggregations that BigQuery keeps up to date incrementally
Looker persistent derived tables and aggregate awarenessPrecomputed results managed in the Looker model

BigQuery features for BI

Materialized views store a query's result and refresh automatically when base tables change. BigQuery can rewrite queries against the base table to read the view instead, which is called smart tuning.

CREATE MATERIALIZED VIEW sales.daily_revenue_mv
OPTIONS (enable_refresh = TRUE, refresh_interval_minutes = 60) AS
SELECT DATE(order_ts) AS order_date, country,
       SUM(amount) AS revenue, COUNT(*) AS order_count
FROM sales.order_facts
GROUP BY DATE(order_ts), country;

BI Engine is an in-memory analysis service. You reserve memory capacity for a project in a location, and it accelerates eligible queries from Looker Studio, Looker and other tools, giving sub-second dashboard response.

Exam tip

"Dashboard is slow and runs the same aggregation many times a day" points to a materialized view. "Interactive dashboard needs sub-second response on BigQuery data" points to BI Engine. They work well together.

Troubleshooting poor performing queries

Open the query's execution details to see stages, slot time, bytes shuffled and any skew. Then apply the fix that matches the symptom.

SymptomFix
Large bytes scannedSelect only needed columns; filter on the partitioning column; cluster on filter columns
One stage far slower than others (skew)A few keys hold most rows; filter or pre-aggregate the hot keys
Slow joinsFilter and aggregate before joining; nest one-to-many data
ORDER BY on huge resultsAdd LIMIT, or sort in the BI tool on a smaller result
Repeated CTE evaluated several timesMaterialize the result in a table
Exact distinct counts are slowAPPROX_COUNT_DISTINCT when small error is acceptable
Queries queue for slotsCheck reservation or on-demand capacity (see the capacity pages)

LIMIT does not reduce bytes scanned on a non-clustered table; it only shortens the output.

Security, masking, IAM and Cloud DLP

NeedControl
Only some datasets or tablesIAM on datasets and tables
A safe subset of a restricted tableAuthorized view in a separate dataset
Each region sees its own rowsRow access policies
Most users see masked emails, a few see real onesPolicy tags with a data masking rule (Masked Reader) and Fine-Grained Reader for the few
Find PII that nobody taggedCloud DLP (Sensitive Data Protection) discovery and inspection
CREATE ROW ACCESS POLICY emea_only
ON sales.order_facts
GRANT TO ('group:emea-analysts@example.com')
FILTER USING (region = 'EMEA');

Masking rules include nullify, SHA-256 hashing and showing only the last four characters. Hashing returns the same value for the same input, so dashboards can still count and group by the masked column.

A worked example

A Looker Studio sales dashboard takes 40 seconds, scans 3 TB per refresh and shows customer emails to every viewer. The engineer creates a materialized view of daily revenue by country and points the dashboard at it.

A BI Engine reservation in the dataset's location gives sub-second charts. The email column gets a policy tag with a hash masking rule, and the data source switches to viewer's credentials so row policies apply per user.

Order facts3 TBMaterialized viewdaily revenueBI EngineLooker Studioviewer credentials

How the exam asks about this

  • "A dashboard repeats the same aggregation over a large, growing table." Create a materialized view and let smart tuning use it.
  • "Analysts may group by email but must not see real addresses." A policy tag with a data masking rule such as SHA-256 hashing.
  • "A query's execution details show one stage where a single worker takes far longer than the rest." Data skew on a join or grouping key; handle the hot keys separately or pre-aggregate.

What to remember for the exam

  • Looker for a governed semantic layer; Looker Studio for quick dashboards; Connected Sheets for spreadsheet users.
  • Precalculate with aggregate tables, materialized views or Looker persistent derived tables.
  • BI Engine adds in-memory acceleration; materialized views refresh incrementally.
  • Read execution details: bytes, slot time, shuffle and skew guide the fix.
  • Mask columns with policy tags, filter rows with row access policies, find PII with Cloud DLP.
Watch out

A Looker Studio data source that uses the owner's credentials shows every viewer the owner's data. Row-level security then filters nothing per viewer.

Common mistakes

Adding LIMIT to cut cost. It does not reduce the bytes a non-clustered table scans.

Copying tables to mask columns. Policy tag masking serves masked values in place.

Buying more slots for a badly written query. Fix the scan and the joins first; capacity is the last step.

Check yourself

  • What does BI Engine do for dashboards?

    It caches data in reserved memory and accelerates eligible BigQuery queries from BI tools, often to sub-second response.

  • How do you let analysts group by an email column without seeing real values?

    Attach a policy tag with a data masking rule such as hashing and grant those analysts the Masked Reader role.

  • Does adding LIMIT reduce bytes billed on a non-clustered table?

    No. BigQuery still reads the selected columns in full; only the output is shorter.

Topic 1 of 3 in Preparing and using data for analysis

Test yourself on Preparing and using data for analysis

The full Google Cloud Professional Data Engineer question bank has 733 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.