Power BI Course · Power Query lesson

Power Query Essentials for PL-300: Clean and Transform Data

Clean a sales table step by step with data types, M transformations, merge versus append and query-folding checks.

Learn the design method, inspect a worked scenario, and test a fresh variation.

POWER BI LESSON PREVIEW
Power Query lessonDesign → test

Core idea

Make source problems visible before loading the model.

Raw CSV → trim + types
Flag invalid price
Load checked rows
Check the model and result.Compare each result with the source rows and filter context.

The direct answer

Transform data without hiding the rows that failed validation.

Power Query prepares data before it reaches the semantic model. For PL-300, that means connecting to sources, profiling columns, setting types, resolving errors and choosing the right transformation. A report measure cannot reliably repair a text amount that should have been numeric or a merge that duplicated facts.

This lesson cleans a small sales example with explicit before-and-after rows and a self-contained M snippet. It also distinguishes merge from append and explains when query folding can matter. The course pricing block follows this introduction.

Course access

Choose your next step in Power BI.

Review the current course options and access details here.

Heycademy Courses · Coming Soon

Master Power BI with Heycademy

We’re preparing an interactive learning experience with practical exercises, skill assessments and personalized learning to help you build confidence and master new skills.

Launching soon!
We’re putting the finishing touches on this course. Please check back for updates.

Original sample

Three rows, one invalid price.

Raw import values before typing
OrderIDQtyTextPriceTextIssue
O1“ 2 ”“10.00”Spaces around quantity.
O2“1”“15.00”Valid text numbers.
O3“3”“bad”Price cannot be parsed.

The target grain is one row per order. The correct line amounts are 20 for O1 and 15 for O2. O3 cannot have a trustworthy line amount until its price is corrected at the source or explicitly handled as invalid. Quietly replacing “bad” with zero would change revenue meaning.

Repeatable cleaning sequence

Profile, trim, type, validate, calculate.

  1. Check row count and OrderID uniqueness in the source.
  2. Trim whitespace from text fields before numeric conversion.
  3. Convert quantity and price to numbers with an explicit error policy.
  4. Flag rows whose conversion failed; do not silently drop them.
  5. Compute line amount only for valid rows and reconcile totals.
Expected after transformation
OrderIDQuantityUnitPriceLineAmountReview
O1210.0020.00Valid
O2115.0015.00Valid
O33nullnullPrice needs correction

A valid-only total is 35, with one unresolved row. It is not the business’s final sales total unless the missing price is resolved or an approved policy explicitly excludes that order.

Self-contained M illustration

Keep an invalid value visible.

let
  Raw = #table({"OrderID", "QtyText", "PriceText"},
    {{"O1", " 2 ", "10.00"}, {"O2", "1", "15.00"}, {"O3", "3", "bad"}}),
  Trimmed = Table.TransformColumns(Raw,
    {{"QtyText", Text.Trim, type text}, {"PriceText", Text.Trim, type text}}),
  Typed = Table.TransformColumns(Trimmed,
    {{"QtyText", each try Number.FromText(_) otherwise null, type number},
     {"PriceText", each try Number.FromText(_) otherwise null, type number}}),
  WithAmount = Table.AddColumn(Typed, "LineAmount",
    each if [QtyText] = null or [PriceText] = null
         then null else [QtyText] * [PriceText], type number)
in
  WithAmount

This M snippet is self-contained: it creates the sample table rather than relying on a local file path. In a real import, preserve error details or separate rejected rows for repair; converting every error to null can otherwise hide whether the problem was missing data or malformed text. Microsoft’s Power Query best practices emphasise types, profiling and step order.

Keep building this skill

Turn the example into a checked report.

Return to the course options whenever you are ready.

Explore course options →

Choose the combine operation

Merge columns; append rows.

Combine-operation decision map
NeedOperationCheck
Add customer region to order rows by CustomerIDMerge.Verify one matching dimension row per key.
Stack January and February sales filesAppend.Verify matching column names and types.
Combine fact and dimension into one giant tableUsually reconsider the model.A star schema may keep roles clearer.

Microsoft’s merge guide documents join kinds and key selection. The append guide explains that columns align by name rather than position. If a merge unexpectedly doubles rows, inspect the right-side key for duplicates before loading.

Query folding and refresh

Know where a transformation runs.

Query folding means supported transformations can be translated to work at the data source. It depends on the connector, source and steps. A CSV has no query engine to receive a folded query. A SQL database may support folding for some filters and projections; inspect the actual query or plan rather than assuming every step folds.

For large database sources, filtering early and preserving foldable steps can reduce transferred data. For this tiny CSV example, folding is not the goal; correct typing and visible errors are. The official Power Query folding documentation explains full, partial and no-folding outcomes. Refresh behavior must also be checked after publishing, because local file paths and credentials may not work in the service.

Your transfer task

Repair O3 and predict the new total.

The source owner corrects O3 price to “12.00.” The expected O3 line amount is 3 × 12 = 36, and total revenue across all three orders is 20 + 15 + 36 = 71. Re-run the transformation and compare row count, parsed values and total.

Show the check

All three rows should now have numeric price and non-null line amount. If O3 remains null, inspect whether the source value actually changed and whether the refresh reached the model. Do not patch the report measure to force 71 while the Power Query output still contains an invalid price.

After the data is clean, the skills-map lesson shows how it becomes a fact table linked to dimensions.

From Power Query to the service

A clean local preview must still refresh.

After publishing, the service needs access to the source and valid credentials. If the source is a local or on-premises file, a gateway or a different supported source location may be necessary. The exact requirement depends on the connector and configuration. Inspect the semantic model’s refresh history and source settings instead of assuming that a successful Desktop preview guarantees service refresh.

Power Query refresh triage
Failure clueFirst checkPotential repair
File path works only on analyst’s laptopWhere the service reads the file.Move to an approved accessible source or configure supported gateway path.
Credential errorSemantic-model source credentials.Update authorised credentials.
Schema changedApplied Power Query steps.Repair renamed or missing columns.
Refresh succeeds but total differsRow count and invalid-value policy.Reconcile refreshed rows with source.

The official scheduled-refresh guide explains service settings. For O3, record whether the price was corrected before or after the last refresh; a stale model may still show null even when the source now says 12.

FAQ

Questions about this skill.

Does Power Query replace DAX?

No. Power Query shapes data before load; DAX calculates results in the semantic model under report context.

Should invalid values be replaced with zero?

Only if an explicit business rule justifies it. Otherwise preserve and repair the data issue.

Can a CSV transformation fold?

A CSV has no source query engine, so it cannot receive folded query operations.

Continue with the course

Build reliable Power BI skills.

Review the course options and choose your next learning step.

Take the next step →
Scroll to Top