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
RD_PowerBI24
Helper I
Helper I

Left side of UK Postcode in PowerBI

Hi,

 

I am trying to extract the left side of the UK Postcode in PowerBI before the space, as per the examploe below of what the output would be in "Area". 

 

Post CodeArea
G1 0LTG1
G2 4PPG2
EH1 1SUEH1
EH7 4GBEH7
G82 4ASG82
EH22 6BDEH22

 

In Excel, I've done this before and using cell A2 as a location reference of the postcode, it is this:

LEFT(A2,FIND(" ",A2)-1) to give outputs such as above.

 

I've tried to do this in PowerBI (N.B. I have 2 postcode columns to merge, hence the IF statement), but with no luck. Can someone point and help me in the right direction:

 

=LEFT(IF(ISBLANK(All_Sales[POSTCODE]),All_Sales[Postcode 2],All_Sales[POSTCODE]),FIND(" ",IF(ISBLANK(All_Sales[POSTCODE]),All_Sales[Postcode 2],All_Sales[POSTCODE]))-1)
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@RD_PowerBI24 lets' try this:

 

LEFT (
    'Table'[All Postcodes],
    FIND ( " ", 'Table'[All Postcodes], 1, LEN ( 'Table'[All Postcodes] ) + 1 ) - 1
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

8 REPLIES 8
parry2k
Super User
Super User

@RD_PowerBI24 lets' try this:

 

LEFT (
    'Table'[All Postcodes],
    FIND ( " ", 'Table'[All Postcodes], 1, LEN ( 'Table'[All Postcodes] ) + 1 ) - 1
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

That worked thank you!

parry2k
Super User
Super User

@RD_PowerBI24 I would recommend creating a sample pbix file with these two columns and sending it over. I think I'm missing something here. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi Parry2k, I don't have the option to do so unfortunately. I'm hoping my example in the first post itself should explain that I just want the left side of a postcode when a gap/space is found inthe postcode.

 

I use 

= FIND(" ",'Table'[All Postcodes],1,BLANK())
This works and gives me the position of the space. But I now need the left side of everything before the space.
 
so "BD20 6TD", space is in position 5, and then my desired output is BD20

 

 

parry2k
Super User
Super User

@RD_PowerBI24 doesn't make any sense? Can you try with ISBLANK () and see if you get the value? Not sure what it is complaining about, assuming Postcode and PostCode 2 columns are of type text and are in the table.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi Parry2k, 

 

The if statement is picking up a postcode from Postcode 2, if POSTCODE is blank/empty, otherwise picks up a postcode from POSTCODE column. I have 2 sales data sources here, hence the use of

IF(ISBLANK(All_Sales[POSTCODE]),All_Sales[Postcode 2],All_Sales[POSTCODE]
 
Therefore, on this output, I want the left side of the postcode, using the FIND function, where it needs to find a space and then I would use the LEFT function to output all the left part of the postcode before the space.
 
Does this help?
 
parry2k
Super User
Super User

@RD_PowerBI24 are you getting errors or incorrect results? Can you make sure All_Sales[POSTCODE] has null (blank) value or is it a space?

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi Parry2k, I get Error when running the FIND function:

RD_PowerBI24_0-1713889469646.png

 

Yes my postcodes do have a space as per the column below:

RD_PowerBI24_1-1713889544345.png

 

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.