# Clean Data in Power Query: Keep Leading Zeros | Storek

> Keep leading zeros, remove duplicates, trim stray spaces, replace bad values and fuzzy-merge messy names in Power Query before your data reaches a report.

Source: https://storek.io/blog/power-query-clean-data-leading-zeros

1.  [Home](https://storek.io/)
2.  [Blog](https://storek.io/blog)
3.  Clean Data in Power Query: Keep Leading Zeros

Platform how-to

# Cleaning data in Power Query before it reaches a report

Most report bugs are cleaning bugs. A few Power Query steps, applied in the right order, catch them before anyone sees a chart.

Storek teamMarch 4, 20254 min read

![Chat card: a dark bubble asks why customers vanish after a merge; ticks show row counts compared and IDs found read as numbers, and the answer blames dropped leading zeros, beside bars of rows after each cleaning step.](https://storek.io/blog/power-query-clean-data-leading-zeros/hero.webp)

Sample dataA cleaning problem found by asking, step by step. Illustrative data.

On this page

1.  [The order matters](#the-order-matters)
2.  [Before and after](#before-and-after)
3.  [Step by step in Power Query](#step-by-step-in-power-query)
4.  [Check your work](#check-your-work)
5.  [When cleaning is the job that never ends](#when-cleaning-is-the-job-that-never-ends)

Dana manages customer data at Fernwood Supply, a regional distributor. Her sales report showed 312 customers in New Jersey; the CRM said 298. After an afternoon of digging she found the culprits: zip codes like 07030 had become 7030, “Acme Corp “ with a trailing space counted as a separate customer from “Acme Corp”, and a handful of rows read “N/A” where a region should be.

None of this was Power BI’s fault. The data arrived messy, and the cleaning hadn’t happened yet. Power Query is the place to do it, before the data reaches the model.

## The order matters

Each step changes what the next one sees. A sensible order:

1.  **Set types**IDs and zips as Text

3.  **Trim and Clean**Spaces and hidden characters

5.  **Replace values**N/A, blanks, typos

7.  **Remove duplicates**On the true key

9.  **Merge**Exact, or fuzzy for names

Trim before removing duplicates, or rows that differ only by a space survive.

## Before and after

CustomerID

Name

Zip

Region

1042

Acme Corp

7030

N/A

01043

Birchwood LLC

08540

NJ

1042

Acme Corp

7030

NJ

Sample dataRaw: lost zeros, a trailing space, a placeholder value and a hidden duplicate.

CustomerID

Name

Zip

Region

01042

Acme Corp

07030

NJ

01043

Birchwood LLC

08540

NJ

Sample dataClean: one row per customer, zeros kept.

## Step by step in Power Query

1.  ### Open Power Query and set types first

    In Power BI Desktop, go to **Home > Transform data**. Look at the **Applied Steps** pane. If there’s an automatic **Changed Type** step, check what it did to ID, zip and phone columns. Select those columns, then use **Transform > Data Type > Text** (or the type icon in the column header). If asked, choose **Replace current** so the earlier conversion is replaced rather than stacked.

    Leading zeros only survive if the column is Text from the start. If the source is a CSV, the zeros are in the file, so fixing the type step brings them back. If the zeros were already lost upstream (in a saved Excel sheet, say), pad them back with **Add Column > Custom Column** and `Text.PadStart([Zip], 5, "0")`.

2.  ### Trim and Clean text columns

    Select the text columns and choose **Transform > Format > Trim** to remove leading and trailing spaces, then **Transform > Format > Clean** to remove non-printable characters such as line breaks. If case shouldn’t matter, add **Format > Capitalize Each Word** or **Uppercase** too.

3.  ### Replace placeholder values

    Right-click the Region column and choose **Replace Values**. Replace “N/A” with nothing, or with the right value if you know it. Repeat for other placeholders like “-”, “TBD” or “unknown”. Blank and null aren’t the same in Power Query, so be consistent about which one you leave.

4.  ### Remove duplicates on the right key

    Select the column (or columns) that should be unique, here CustomerID, and choose **Home > Remove Rows > Remove Duplicates**. Power Query keeps the first occurrence and compares text case-sensitively, which is why trimming and case come first. To review the duplicates before deleting them, use **Home > Keep Rows > Keep Duplicates** on a copy of the query.

5.  ### Merge with fuzzy matching when names are typed by people

    To bring in data from another list that only shares a company name, use **Home > Merge Queries**. Pick the matching columns, then tick **Use fuzzy matching to perform the merge**. Under fuzzy options you can set a similarity threshold, ignore case and ignore spaces. Start strict, review the matches, then loosen if needed. For IDs, prefer an exact merge on cleaned keys.

## Check your work

-   Count rows before and after Remove Duplicates, and spot-check what was dropped.
-   Use **View > Column quality** and **Column distribution** to see errors, empties and distinct values per column.
-   Confirm that keys you’ll relate later have the same type in both tables. Mismatched types are a common cause of Power BI numbers that don’t match Excel and of accidental many-to-many relationships.

Once tables are clean, split them into facts and dimensions with [star schema basics](https://storek.io/blog/power-bi-star-schema-basics), and if a source arrives with one column per month, unpivot it next.

## When cleaning is the job that never ends

The trouble with cleaning steps is that each new export, or each new person’s spreadsheet, brings a slightly different mess. We wrote about that pattern in scattered spreadsheets to one picture.

If keeping up with it is too much, Storek can take it on. You add your files to [one place](https://storek.io/platform/lake), it notices when a column changes shape and checks every load’s row count against the source. Then you can [ask questions in plain words](https://storek.io/platform/ask) on data that’s already tidy.

About the examples

The company, people and figures in this article are illustrative.

## Sources

1.  [Data types in Power Query](https://learn.microsoft.com/en-us/power-query/data-types) · Microsoft Learn · checked November 13, 2026
2.  [Working with duplicate values](https://learn.microsoft.com/en-us/power-query/working-with-duplicates) · Microsoft Learn · checked November 13, 2026
3.  [Fuzzy merge](https://learn.microsoft.com/en-us/power-query/merge-queries-fuzzy-match) · Microsoft Learn · checked November 13, 2026

Data pipelinesData loadingBI tools

## Keep reading

[Platform · The sorting office**Bring any file or system. Storek sorts it.**Open the page →](https://storek.io/platform/lake)[Platform how-to**From Scattered Spreadsheets to One Picture**Read the article →](https://storek.io/blog/scattered-spreadsheets-to-one-picture)[Platform how-to**Make Sense of Very Wide Exports Without the Grind**Read the article →](https://storek.io/blog/wide-export-lookup-table-unpivot)

FAQ

## Questions, answered.

How do I keep leading zeros in Power Query?

Set the column's data type to Text before any step converts it to a number. If Power Query added an automatic Changed Type step that made the column a number, edit or delete that step, then set the type to Text. Once zeros are dropped, they can't be recovered from the number.

Is Remove Duplicates in Power Query case-sensitive?

Yes. Power Query compares text case-sensitively, so 'ACME' and 'Acme' are different values. Use Transform > Format > Lowercase, Uppercase or Capitalize Each Word first if case should not matter.

What is the difference between Trim and Clean?

Trim removes leading and trailing spaces. Clean removes non-printable characters such as line breaks that sometimes come in from copied text. Both are under Transform > Format.

When should I use fuzzy matching in Merge Queries?

When the key you're joining on is a name typed by people, like a company name, and small spelling differences should still match. Set a similarity threshold and review the matches; for IDs, clean them and use an exact merge instead.

Book a demo

## See your own data, delivered.

30 minutes. Your data or our sample. No slide deck. Pick a time straight after the form.
