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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

UK Post Codes

Hi there,

 

I have some data that includes full post code, but I'm trying to find a way to just pull the postal area (either first letter or first 2 letters) into a new column.

I've looked at LEFT functions but couldn't figure out a way to do both.

 

Any ideas would be very much appreciated.

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

You can also achieve this via creating a calculated column using DAX:

POSTCODEnew =
IF (
    RIGHT ( LEFT ( 'UK Post Code'[POSTCODEold], 2 ), 1 )
        IN { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
    LEFT ( 'UK Post Code'[POSTCODEold], 1 ),
    LEFT ( 'UK Post Code'[POSTCODEold], 2 )
)

1.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

12 REPLIES 12
SivaMani
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

Use Split column option (Edit Quries -> Split Column)

Split Column.gif 

 

Regards,

Siva

Anonymous
Not applicable

This is a great option, but I want to leave the original data in one column, and then split into another, like below.

 

POSTCODEold       POSTCODEnew

DW1 2ZZ               DW

A22 2BB                A

X33 5ZZ                X

PB4 0XX                PB 

Simply create the duplicate column (Right click on POSTCODEold -> Duplicate Column). Split the column and delete the unwanted column.

 

That's it

Hi @Anonymous,

 

If it is working fine, close the thread by accepting the solution.

 

Thanks,

Siva

 

Anonymous
Not applicable

hi @SivaMani

 

This doesnt solve the problem I have but is a great tool to use for other issues.

Alternative solution:

 

let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "POSTCODEnew", each List.First(Text.SplitAny([POSTCODEold],"0123456789")))
in
    #"Added Custom"
Specializing in Power Query Formula Language (M)
Anonymous
Not applicable

Thank you @MarcelBeug

 

I will try this in a little while and see what happens.

 

Really appreciate the reply.

Hi @Anonymous,

 

You can also achieve this via creating a calculated column using DAX:

POSTCODEnew =
IF (
    RIGHT ( LEFT ( 'UK Post Code'[POSTCODEold], 2 ), 1 )
        IN { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
    LEFT ( 'UK Post Code'[POSTCODEold], 1 ),
    LEFT ( 'UK Post Code'[POSTCODEold], 2 )
)

1.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yulgu-msft 

How can I do this in a measure please?  My company don't allow me to create columns in certain datasets we use.

Thanks

Anonymous
Not applicable

hi  @v-yulgu-msft

 

That has worked perfectly. Very much appreciated Yuliana.

 

Have a great day.

Here's another option....

 

Post Code Area =
   VAR PCD = [Post Code District]
   VAR C2 = MID(PCD,2,1)
RETURN
SWITCH(
   TRUE(),
      SEARCH(C2,"0123456789",1,0) >= 1,LEFT(PCD,1),
      LEFT(PCD,2)
)

Still, Power Query would be the more appropriate environment for this kind of transformations.

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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