Skip to content

Profile and Clean Data in Power Query

Step 3 of 24

PL-300: Profile and Clean Data in Power Query

Find data quality problems before loading

A column can look clean in the preview and still contain invalid dates or repeated keys further down. Profiling and cleaning data in Power Query helps you find those problems, choose a repair that preserves the intended rows, and check the result.

This lesson covers Profile and clean the data in the PL-300 Prepare the data domain (25–30% of the exam, skills measured from April 20, 2026). You will use column quality, distribution, and profile to investigate inconsistent values, missing data, and import errors.

Learning objectives

  • Turn on and interpret column quality, column distribution and column profile.
  • Explain how profiling scope (first 1,000 rows versus entire data set) can mislead.
  • Resolve inconsistent values, duplicates, nulls and invalid values with the appropriate Power Query transformation.
  • Diagnose and resolve import errors such as type conversion, missing columns and refresh failures.

1. Profiling the data

Profiling happens in the Power Query Editor (Home → Transform data). On the View tab, use Data preview in Desktop or the Data view menu in Power Query Online. Three options help you inspect columns:

Option What it shows Use it to
Column quality Quality categories such as Valid, Error, and Empty; the tool can also flag Unknown or Unexpected error Spot errors and missing values quickly
Column distribution A histogram of value frequency plus counts of distinct and unique values Detect keys, duplicates, skew and category explosion
Column profile A detailed pane for one selected column: statistics (count, errors, empty, distinct, unique, min, max, average, standard deviation) and a value distribution chart Investigate one column deeply

Column quality and column distribution under each header in Power Query Online: valid, error and empty percentages, distinct and unique counts

Definitions the exam likes: distinct values counts each different value once (A, A, B has 2 distinct), whereas unique values counts values that appear exactly once (A, A, B has 1 unique). For a candidate key, first check for nulls, blanks, and errors. Then verify on the full result that every key occurs exactly once.

Column profile pane for the Amount column: count, errors, nulls, distinct and unique values, with the N/A placeholder dominating the value distribution

By default, profiling is based on the first 1,000 rows. The status bar at the bottom of the editor shows "Column profiling based on top 1000 rows". Click it and choose Column profiling based on entire data set to analyse everything. The first 1,000 rows are not a representative sample by design. An error later in the data can be missed and may surface during load or refresh. Full profiling can cost time on a large source.

Status bar menu to switch column profiling from the top 1,000 rows to the entire data set

Example. Contoso Health loads a patient visits table with 3 million rows. The column quality for VisitDate shows 100% valid in the top 1,000 rows. After switching to the entire data set, 2.3% of values show errors, caused by dates stored as 31/02/2025 in a legacy import. In this example, full profiling reveals the problem. Investigate the error rows and check the source format before loading the model.

Two other helpers: the Query Dependencies view (View → Query dependencies) shows how queries relate, and the Query Diagnostics tools help find slow steps. For limiting the preview cost during development you can keep the top-1,000-row profile and validate on the full data set before publishing.

2. Evaluating quality and distribution

Look for these signals:

  • Errors (red) in column quality: conversion failures, division by zero, missing fields in an expanded record.
  • Empty (dark grey): investigate missing values. In a text column, check separately for null, zero-length strings, and whitespace.
  • Skewed distribution: one value dominating (for example 98% "N/A") suggests a placeholder.
  • Unexpected distinct count: Country with 240 distinct values when 60 are expected is a signal to investigate spelling variants, invalid codes, or changes in scope.
  • Min/max outside the expected range: ages of -1 or 999 are sentinel values.
  • Leading or trailing spaces, mixed case, and control characters: inspect how values compare at the merge or relationship step; differences can cause mismatches.

Exam tip: the question often asks for the first step. Profiling (column quality/distribution/profile) comes before cleaning, and full-data-set profiling comes before trusting a quality percentage.

3. Resolving inconsistencies, nulls and quality issues

Text inconsistencies

Under Transform → Format: Trim removes leading and trailing spaces, Clean removes non-printing characters, and lowercase / UPPERCASE / Capitalize Each Word standardise case. Use Replace Values (right-click a column) to map variants ("U.S.A.", "USA") to one value. For many variants, create a maintained mapping table with one row per raw value and merge it into the source. See transforming and loading data with Power Query for join types and unmatched rows.

Transform column, Text transforms menu: lowercase, UPPERCASE, Capitalize Each Word, Trim and Clean

Replace values dialog replacing the text "two" with 2 in the Quantity column

Power Query is case-sensitive for text comparisons. Normalize both join keys where the business treats case or spacing as equivalent, and validate the result. A semantic model relationship is a separate operation; text loaded into the Power BI model is generally compared without regard to case.

Duplicates

Remove Duplicates (Home → Remove rows) removes entire rows based on the selected columns. Selecting all columns removes exact duplicate rows. Selecting only a key can discard conflicting records, and Power Query does not guarantee which row survives. If the latest record must win, define an explicit per-key ranking with a stable tie-breaker and verify the result. Normalize case only if the identifiers are meant to be equivalent.

Table menu with Keep duplicates, Keep errors, Remove duplicates and Remove errors

Nulls and empty values

Goal Transformation
Fill blanks from the value above (grouped headings in Excel) Fill Down for a value above; Fill Up for a value below. Convert empty text to null first if needed.
Replace null with a default such as 0 Replace Values: replace null with 0 (type must be consistent)
Handle a missing key Inspect or quarantine the row; filter it out only if the business rule allows it
Keep them but make intent explicit Replace with "Unknown" for text categories

Column quality tooltip for Quantity: 91% valid, 9% empty, with a Remove empty shortcut

Empty strings ("") differ from null. A text column may need Replace Values for both, or a custom column using if [Col] = null or [Col] = "" then "Unknown" else [Col].

Invalid values and errors

  • Replace Errors converts error cells to a chosen value; use it deliberately because it hides the cause.
  • Remove Errors drops the whole row, which can silently remove valid data from other columns.
  • Keep Errors isolates problem rows so you can see them and fix the source.
  • Use a conditional or custom column for rules such as “ages outside the agreed range become null.” Check nulls explicitly before numeric comparisons.

Worked example 1: cleaning a country column. Scenario. A Customers table has a Country column with "France", "france ", "FR", "United States", "USA", "U.S." and blanks. Column distribution shows 41 distinct values for about 20 real countries. The analyst must produce a clean column that can relate to a Country dimension.

Reasoning.

  1. Trim and Capitalize Each Word on Country to remove spaces and case variance ("france " becomes "France").
  2. Replace Values for known codes: FR → France; USA and U.S. → United States.
  3. Map null and "" to the same Unknown key used by an explicit Unknown row in the dimension. Replacing blanks in the fact alone does not create a match.
  4. Re-check column distribution: distinct count should now be about 21 (20 countries plus Unknown).
  5. If many variants remain, load a mapping table and merge on the raw value to return the standard name, which is easier to maintain than dozens of Replace steps.

Why alternatives are worse. Removing rows with unmatched countries loses sales. Fixing the values in DAX with a calculated column duplicates cleaning in the model and increases model size. Editing the source file by hand does not survive the next export.

4. Resolving data import errors

Errors fall into several families.

Error type Typical cause Fix
DataFormat.Error: We couldn't convert to Number Text such as "N/A", "1,234.5" in a wrong locale Replace the text first, or set the type Using Locale
Expression.Error: The column 'X' of the table wasn't found Source column renamed or removed Map an approved source alias to the expected name and fail clearly if a required column is missing
DataSource.Error / credentials Path moved, password expired, file open or deleted Fix in Data source settings and re-enter credentials
Expression.Error: ... Record / expanded field missing Semi-structured data with varying keys Normalize optional fields before expansion, for example with Record.FieldOrDefault; investigate missing required fields separately
Rows loaded with wrong header First rows contain titles Use First Row as Headers after removing top rows
Refresh timeout / out of memory Heavy steps that do not fold Filter early, remove columns, push work to the source

Sheet loaded without promoted headers: Column1 to Column6, with the real headers in the first row

Type conversion with locale

A date such as 03/04/2025 means 3 April in the UK and 4 March in the US. Use Change Type → Using Locale and choose the locale of the source (for example English (United Kingdom)). The wrong locale can silently swap day and month for an ambiguous value, or return an error when the date is invalid under that locale. Compare against known source examples.

Change column type with locale: Date with English (United Kingdom), showing the expected input formats

try ... otherwise

M offers try expression otherwise fallback to handle errors per value. This example parses amounts from a French source:

M
= Table.AddColumn(Previous, "Amount", each try Number.From([RawAmount], "fr-FR") otherwise null, type nullable number)

This substitutes null for a conversion error. Keep the raw column and use a separate try result or error flag to distinguish conversion failures from source nulls. Count failures before discarding any detail.

Custom column AmountClean with the formula try Number.From([Amount], "fr-FR") otherwise null

Reading errors in the interface

Click the word Error in a cell to see the message in the preview pane. Use Keep Errors (Home → Keep rows) to list only error rows. For a refresh error in the service, start with the semantic model’s Refresh history and error details. Inspect the relevant applied steps for data errors. For gateway or credential errors, check connect to data and configure credentials in Power BI in the service.

Error details: DataFormat.Error, We couldn't convert to Number, with Detail N/A

Keep errors result: only the rows whose Amount failed to convert, next to the AmountClean column produced by try ... otherwise

Worked example 2: a refresh that suddenly fails. Scenario. A monthly refresh of a model fed by an Excel file fails with "The column 'Revenue' of the table wasn't found". The finance team renamed the column to Total Revenue in the file. How should the analyst fix it, and how can they reduce repetition of the problem?

Reasoning.

  1. Open the failing query in Power Query. The step Changed Type or Renamed Columns references Revenue.
  2. Rename the source reference to Total Revenue, or add a step that renames Total Revenue to Revenue so the rest of the model stays unchanged.
  3. Confirm that the downstream steps and measures still use Revenue.
  4. To prevent recurrence, agree a template with finance, or use Table.RenameColumns(Source, {{"Total Revenue", "Revenue"}}, MissingField.Ignore) if the input has exactly one of the two names. If both are present, define which column is authoritative; if neither is present, report a missing required column.
  5. Republish and refresh.

Why alternatives are worse. Deleting the step breaks the data type. Re-importing a new query creates a second table and breaks relationships and measures. Waiting for finance to revert is not a robust process.

5. Comparison: ways to handle bad values

Approach Keeps the row? Hides the cause? Use when
Remove Errors No Yes, unless retained elsewhere The data owner agrees to exclude the rows and you have measured the impact
Replace Errors Yes Yes A safe default exists (0, null, "Unknown")
Keep Errors Only error rows No Investigating
try ... otherwise Yes Partly Per-value fallback with documented loss
Fix at source Yes No Best long-term solution

6. Pitfalls and exam tips

  • Do not trust the default top-1,000-row profile for a large table.
  • Replace blanks and nulls deliberately; a numeric column with nulls averages differently from one with zeros.
  • Clean text before merging, removing duplicates or creating relationships.
  • Avoid Remove Errors when other columns in the row are valid.
  • A wrong locale can produce plausible but wrong values; check known dates and numbers after conversion.
  • Exam tip: when two answers fix the problem, prefer the one applied earliest in the pipeline (source or Power Query) over a DAX workaround, because cleaning once is cheaper than repairing every measure.

7. Mini case study

Case. Tailwind Airlines imports a Bookings CSV. Column quality shows 4% errors in FareAmount (values such as "USD 120.50"), 12% empty PassengerEmail, repeated BookingID values, and Departure dates such as 05/06/2025. The source owner confirms the dates use UK conventions. The initial profile is limited to the first 1,000 rows.

Tasks. Describe what to do, in order.

Solution.

  1. Switch profiling to the entire data set to confirm the counts.
  2. FareAmount: use Replace Values to remove the "USD " prefix (or split by a delimiter), then parse the amount using the source’s numeric locale. Keep the currency code separately if currencies vary; a type conversion does not convert currency. Check remaining errors with Keep Errors.
  3. PassengerEmail: If email is optional, keep the missing values and the booking rows. Add a separate display category if needed.
  4. BookingID: it should be unique. Investigate with Group By (count rows per ID) to see if duplicates are exact copies or different bookings. Remove only confirmed duplicate rows. If the ID repeats for legitimate lines or conflicting updates, establish the intended grain or resolution rule with the owner.
  5. Departure: Change Type → Using Locale with English (United Kingdom) so 05/06/2025 is 5 June.
  6. Validate by profiling again: check error counts and reconcile affected rows. If the expected grain is one row per booking, verify a non-null, unique BookingID across the full result.

8. Extra practice: profiling a sales feed end to end

Scenario. Litware Outdoor receives a daily OrderLines export with 1.8 million rows. The BI developer must decide whether it is safe to load. A repeatable routine saves time on the exam and in real projects:

  1. Shape first. Check the row count, column count and header row. If titles sit above the header, remove top rows and promote headers.
  2. Keys. Turn on column distribution for OrderLineID. If distinct is lower than the row count, duplicates exist; if unique is lower than distinct, some IDs repeat. Decide whether rows are true duplicates (remove) or legitimate split shipments (keep, and use a composite key).
  3. Measures. Open column profile for Quantity and UnitPrice. A minimum of -5 may be returns, which is valid, whereas a maximum of 99999 repeated hundreds of times is a sentinel value that should become null.
  4. Dates. Verify the range: a minimum of 1900-01-01 usually reveals a default date from the source system. Confirm with the source owner before replacing it with null.
  5. Categories. Look at distinct counts for ProductCategory and Region. Unexpected extras mean spelling variants; compare to the dimension table.
  6. Text hygiene. Apply Trim and Clean to every text column that will be used as a key or in a relationship.
  7. Document. Name the steps clearly (for example "Replace 1900 dates with null") so a reviewer understands the intent. The Applied Steps list is part of the solution quality.
Finding Likely meaning Action
Distinct count much higher than expected Spelling or case variants Trim, case, Replace Values or mapping table
100% empty column Possibly unused or missing upstream Check whether it is required; remove it only if it is unused
Few distinct values in a numeric column Actually a category (status code) Change type to text so it is not aggregated
Errors only after full-data profiling Late-appearing bad rows Fix before publishing

Removing columns that contain nothing useful is also a performance technique: smaller models refresh faster and use less memory, which comes back in the lesson on model optimisation.

Key terms

  • Column quality / distribution / profile: profiling views in Power Query.
  • Distinct vs unique: different values counted once vs values appearing exactly once.
  • Null vs empty string: missing value vs zero-length text.
  • Locale: culture used to parse dates and numbers.
  • Fill Down: copies the previous non-null value into nulls.

Summary checklist

  • I can enable the three profiling options and switch to entire-data-set profiling.
  • I can tell distinct from unique and use them to validate keys.
  • I can trim, clean, standardise case and replace values before merging.
  • I can choose between Remove, Replace and Keep Errors with their consequences.
  • I can fix type conversion, locale and missing-column refresh errors.

Official sources