jorelle domingo.POWER QUERY PRACTICE LAB

FOR EXCEL & POWER BI LEARNERS

Power Query practice exercises
with solutions.

Work through messy data. Make the cleaning decisions. Check your result against a worked answer.

Free exercise: no email required. Full pack: one-time purchase; tax may apply.

A COMPLETE FREE EXERCISE

Clean text without losing missing-value evidence

Download sample files ZIP · PDF + CSV + M

A small workshop receives a contact export. Names and region codes contain stray spaces, empty strings, and true nulls.

Your task
Produce one clean row per contact and a NameState column showing what was missing before cleaning.

The rules

  • Keep all eight rows and keep ContactID as text, including leading zeros.
  • Classify the original Name: null becomes Null; empty or whitespace-only text becomes Blank; other text becomes Present.
  • Trim only the beginning and end of Name and Region. Preserve internal spaces, apostrophes, and spelling.
  • Convert cleaned empty text to null. Uppercase the cleaned Region.
  • Return ContactID, Name, Region, NameState sorted by ContactID.

Start the query

Open a blank query, open Advanced Editor, and replace its contents with the starter below. It includes the exact source data, so you need no file paths. Apply your transformations before opening the solution.

In the optional raw CSV, <NULL> represents a true null and an empty field represents empty text. The embedded starter preserves both exactly.

Show the starter M query
Download .pq
// Original synthetic practice data. Paste the entire query into Advanced Editor.
let
    Source = #table(type table [ContactID = text, Name = nullable text, Region = nullable text], {
        {"0001", "  Mina Patel  ", " NORTH "},
        {"0002", "", "south"},
        {"0003", null, "  EAST"},
        {"0004", "   ", "west "},
        {"0005", "#(tab)Ari Chen#(tab)", " north#(tab)"},
        {"0006", "Sam  Lee", "south"},
        {"0007", "  Jo O'Neil", ""},
        {"0008", "Ren Diaz ", null}
    })
in
    Source

Need a nudge?

Use one hint, then try another step before revealing the next.

Hint 1

Start with the missing-value flag before changing the original Name.

Hint 2

Text.Trim removes surrounding whitespace; an empty string still differs from null.

Hint 3

Use a nullable-text helper: return null for null or a trimmed empty string; otherwise return the trimmed value.

Reveal the worked solution

Why these steps work

  1. Add NameState from the raw Name so cleaning does not erase whether a missing value was null or blank.
  2. Write a reusable nullable-text cleaning function so both columns follow the same blank policy.
  3. Apply the helper to Name and Region. Keep identifiers out of numeric conversion so 0001 remains 0001.
  4. Uppercase Region to remove case differences while leaving names unchanged.
  5. Sort on ContactID and check state counts; unchanged row count proves this is cleaning rather than filtering.

Common trap: Replacing every blank with null before adding NameState destroys the evidence needed to distinguish the two cases.

Download .pq
// Reference solution: documented M; not executed in a native Power Query engine.
let
    Source = #table(type table [ContactID = text, Name = nullable text, Region = nullable text], {
        {"0001", "  Mina Patel  ", " NORTH "},
        {"0002", "", "south"},
        {"0003", null, "  EAST"},
        {"0004", "   ", "west "},
        {"0005", "#(tab)Ari Chen#(tab)", " north#(tab)"},
        {"0006", "Sam  Lee", "south"},
        {"0007", "  Jo O'Neil", ""},
        {"0008", "Ren Diaz ", null}
    }),
    Flagged = Table.AddColumn(Source, "NameState", each if [Name] = null then "Null" else if Text.Trim([Name]) = "" then "Blank" else "Present", type text),
    Clean = (s as nullable text) as nullable text => if s = null then null else if Text.Trim(s) = "" then null else Text.Trim(s),
    Trimmed = Table.TransformColumns(Flagged, {{"Name", Clean, type nullable text}, {"Region", Clean, type nullable text}}),
    Upper = Table.TransformColumns(Trimmed, {{"Region", each if _ = null then null else Text.Upper(_), type nullable text}}),
    Result = Table.Sort(Upper, {{"ContactID", Order.Ascending}})
in
    Result

Expected output

Compare all values and counts. Here, null means a missing value. Internal spaces are preserved.

ContactIDNameRegionNameState
0001Mina PatelNORTHPresent
0002nullSOUTHBlank
0003nullEASTNull
0004nullWESTBlank
0005Ari ChenNORTHPresent
0006Sam LeeSOUTHPresent
0007Jo O'NeilnullPresent
0008Ren DiaznullPresent
  • 8 output rows; NameState counts: Present 5, Blank 2, Null 1.
  • 0001 becomes Mina Patel / NORTH; 0006 remains Sam Lee with two internal spaces.
  • 3 cleaned names and 2 cleaned regions are null.

Try one change: Add a contact whose name is only a tab. Predict its NameState before you refresh. Then explain why it differs from a true null.

Reference outputs are independently calculated in Python; M syntax is checked with Microsoft’s parser. These queries have not been run in a native Excel or Power BI engine.

Microsoft documentation: Text.Trim · Table.TransformColumns

THE FULL PRACTICE PACK

Ten challenges.
A clear way to check each one.

$7 USD

Get the workbook · $7 USD ↗

One-time purchase. Tax may apply.

For learners who know the editor basics and want hands-on practice. Each challenge includes a brief, graduated hints, explained steps, a complete M query, source CSVs, and expected outputs.

Actual workbook page 4: the first challenge, rules, checks, and hints
The task, rules, and hints · page 4
Actual workbook page 15: the worked explanation and reference output for challenge one
The worked explanation · page 15

Actual pages from the 25-page workbook. Select a page to read it at full size.

  1. 01

    Clean text without losing missing-value evidence

    Produce one clean row per contact and a NameState column showing what was missing before cleaning.

    Beginner
  2. 02

    Parse dates with an explicit locale

    Add a typed BookingDate and a DateStatus without dropping invalid or missing source rows.

    Beginner
  3. 03

    Parse amounts and quarantine bad records

    Return a record with Valid and Rejected tables, preserving the raw values and a clear parse status.

    Beginner
  4. 04

    Unpivot monthly columns while preserving zero

    Create a tidy table with one row per reported branch-month, ready for a chart or grouped calculation.

    Beginner
  5. 05

    Fill section labels and remove report furniture

    Assign every product line its region, then remove repeated headers and subtotals without double counting.

    Beginner
  6. 06

    Join a lookup without losing or multiplying orders

    Enrich every order with customer details, expose unmatched keys, and fail clearly if the lookup key is not unique.

    Intermediate
  7. 07

    Keep the latest record with a deterministic tie-break

    Return one current ticket record using timestamp first and sequence second, with an explicit guard against unresolved ties.

    Intermediate
  8. 08

    Split tags into rows and deduplicate within each record

    Build a two-column bridge table with one unique normalized RecordID-Tag pair per row.

    Intermediate
  9. 09

    Reconcile different schemas before appending

    Normalize both sources into one canonical schema and append all transactions with consistent types.

    Intermediate
  10. 10

    Capstone: reconcile orders and payments with an audit trail

    Produce a reconciliation table plus three review queues that account for every supplied source row.

    Intermediate

Included
PDF workbook · 10 starter queries · 10 worked M solutions · original CSV datasets · expected output CSVs

Format & compatibility
Downloadable ZIP and PDF. Designed for desktop Excel for Windows with Power Query and Power BI Desktop. Mac and web workflows are not covered.

What should I know before buying?

You should be able to create a blank query and open Advanced Editor. This is a practice workbook, not a video course or an .xlsx template. The full code is supplied as plain-text .pq files. Some exercises return a record of tables, with instructions for inspecting each output.

All datasets are fictional. The solutions have been syntax-checked and reference results calculated independently, but have not been executed in a native Microsoft Power Query engine. The download explains the validation scope.