Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JWorthy
Advocate I
Advocate I

Formatting Postcodes

Hello,

 

I have a .csv of delivery information with postcodes that I need to format correctly before I import into Power BI.

 

Below are the different incorrect ways that postcode information can come to me incorrect and how I'd like to fix the postcodes.

 

Record #Postal Code_Incorrect (how i receive them)Postal Code_Fixed (what I want to transform them into).
1A99AAA9 9AA
2A999AAA99 9AA
3AA99AAAA9 9AA
4AA999AAAA99 9AA
5A9A9AAA9A 9AA
6AA9A9AAAA9A 9AA
79999999999

 

How can I correctly format the postcodes?

 

I'm really new to Power BI so in any response please assume I'm a total idiot - as basic instructions as possible please.

 

Thanks for your help 🙂

 

J

1 ACCEPTED SOLUTION
FrankAT
Community Champion
Community Champion

Hi,

  1. Open Power Query editor.
  2. Select column 'Postal Code_Incorrect (how i receive them)'.
  3. Change data typ to text.
  4. Tab Add Column > Column From Examples
  5. Enter in the first row the postal code A9 9AA, press Enter.
  6. Enter in the second row the postal code A99 9AA, press Enter.
  7. Ok.
  8. Tab Transform > Format > UPPERCASE.
  9. Done!

13-02-_2020_16-45-36.png

 

Regards FrankAT

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

Try a new column like

new column =left(table[Postal Code],search("9AA",table[Postal Code],1,len(table[Postal Code]))) & " "& if(search("9AA",table[Postal Code],1,-1)>0,"9AA","")

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
FrankAT
Community Champion
Community Champion

Hi,

  1. Open Power Query editor.
  2. Select column 'Postal Code_Incorrect (how i receive them)'.
  3. Change data typ to text.
  4. Tab Add Column > Column From Examples
  5. Enter in the first row the postal code A9 9AA, press Enter.
  6. Enter in the second row the postal code A99 9AA, press Enter.
  7. Ok.
  8. Tab Transform > Format > UPPERCASE.
  9. Done!

13-02-_2020_16-45-36.png

 

Regards FrankAT

Hi Frank,

 

Thank you for your example it was helpful. When I did this to my dataset the rule it created only created an if>then clause for all the postcodes containing errors.

This means I have to manually check when I append data. Is this because I had too few erroneous examples to work from? Would it be better to remove all spaces in the correct postcodes and then complete?

 

If not do you know how I could create a more substantial rule? I think for my data a rule where there's a space before the last 3 characters would fix all errors.

 

Screenshot added with fictional values to illustrate. 

Column from examples screenshot.png

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.