Ravindra BagaleCourses & study guides मराठी Track your progress

5. Data Cleaning A–Z

5.12 Pincodes and Codes with Leading Zeros

Codes with leading zeros using TEXT with example — in 30 seconds

What: TEXT with a format like "000000" adds the missing zeros in front of a code and returns it as text.

Why: Excel drops leading zeros from numbers. Product code 000451 becomes 451, and lookups against the master fail.

Tiny example: =TEXT(C2,"000000") turns 451 into 000451 and 12 into 000012.

First look at the data (before → after):

Codes with leading zeros using TEXT with example: before and after tables, fictional FreshGo Maharashtra data

Expected result — Six-character codes

C: Code D: Fixed code LEN
451 000451 6
12 000012 6
4100 004100 6

About this data: Teaching sample for a fictional shop “Skyline Clinics”. Figures and names (e.g. Neha Shah) are made up for this lesson on pincodes and codes with leading zeros.

Before table and formula as text

Before — Product codes after import (zeros lost)

C: Code
451
12
4100

About this data: Demo table only — not real customer or company data. Built to practise pincodes and codes with leading zeros.

Formula / click path

D2: =TEXT(C2,"000000")
check: =LEN(D2)=6

Do it step by step:

  1. Click D2 and type =TEXT(C2,"000000").
  2. Copy down.
  3. Check the length with =LEN(D2)=6. Every row should say TRUE.
  4. Copy column D and Paste Special › Values over column C.
  5. Next time, set the column to Text in Power Query or the import wizard before loading.

Indian PIN codes are 6 digits and never start with 0 (Maharashtra PINs start with 4), but exports still damage them – and product or employee codes often do start with zeros.

Before

Store Pincode (raw) SKU (raw)
Kothrud 411038.0 4512
Gangapur Road 422 013 87
Sitabuldi 440012 1203
Hotgi Road 41 3003 9

About this data: Made-up rows so you can copy the pattern for pincodes and codes with leading zeros. Currencies may use ₹, £, € or $.

After

Store Pincode SKU
Kothrud 411038 004512
Gangapur Road 422013 000087
Sitabuldi 440012 001203
Hotgi Road 413003 000009

About this data: Fictional worksheet used in class. Safe to edit; nothing here is live production data.

Steps in Excel

  1. Pincode as clean 6-character text: =TEXT(VALUE(SUBSTITUTE(B2," ","")),"000000"). Check =LEN(C2)=6.
  2. SKU with leading zeros restored as text: =TEXT(C2,"000000").
  3. If the code only needs to look padded but stay a number: custom format 000000 (1.6).
  4. Import tip: in Power Query or the Text Import Wizard set these columns to Text so zeros are never lost.

Ravindra Bagale's Tip

When a CSV is opened in Excel by double-clicking, many students' codes turn from "004512" into "4512", and then they don't match the master. When importing columns that contain codes, set them as Text (Data › From Text/CSV or Power Query). And remember – even if a format shows the zero, the value is still a number; a lookup needs the same type on both sides.

Practice task

Restore 6-digit SKUs from numbers, clean pincodes with spaces and ".0", and verify that all pincodes in the Pune list start with 411 using =LEFT(C2,3)="411".

Loading practice tasks...

  1. Fix a US ZIP (Easy): Show C3 as 5 digits.
  2. Fix a short ZIP (Easy): Show C5 as 5 digits.
  3. Item code with zeros (Easy): Show E2 as 6 digits.
  4. Length of a number (Easy): How many digits does C3 show?
  5. Is it a number or text? (Medium): Is D3 text? (TRUE or FALSE)
  6. Do they match? (Medium): Show C5 as a 5-digit code with leading zeros. Is it the same as D5? (TRUE or FALSE)
  7. Item code with prefix (Medium): Make "SKU-000123" from E4.
  8. Zeros with RIGHT (Medium): Show E3 as 6 digits using RIGHT.
  9. Right length by country (Hard): Show C4 with the right length for its country (B4).
  10. Same for a US row (Hard): Show C3 with the right length for its country.
  11. Count lost zeros (Hard): How many numbers in C2:C7 are shorter than 5 digits?

Quick revision cards

Three standalone cards. Each one explains the idea with its own example. Scan the QR to open this lesson.

Revision card 1: What is Pincodes And Codes With Leading Zeros?
Card 1: What is Pincodes And Codes With Leading Zeros? · Download PNG
Revision card 2: Tiny example — Pincodes And Codes With Leading Zeros
Card 2: Tiny example — Pincodes And Codes With Leading Zeros · Download PNG
Revision card 3: Checklist — Pincodes And Codes With Leading Zeros
Card 3: Checklist — Pincodes And Codes With Leading Zeros · Download PNG