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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
AOD
Helper III
Helper III

Add space in text field

Hi All,

 My requirement is to add space in  the text field on one of the column of table.

Eg: I have postcode as text field  as B30123 , B9234

 

I want new column to be created which will check length of the field value and add space

 

Eg B30123 - Length is 6 so i want new value to be B30 123

B9234 - Length 5 -> B9 234

 

Thanks for your

 

 

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @AOD ,

 

In Power Query, you can add a new custom column and write code something like this:

 

 

 

=
if Text.Length([postcode]) = 6 
then Text.Combine({Text.Start([postcode], 3), Text.End([postcode], 3)}, " ")
else if Text.Length([postcode]) = 5 
then Text.Combine({Text.Start([postcode], 2), Text.End([postcode], 3)}, " ")
else "Another pattern")

 

 

 

 

This gives me the following output:

AOD.PNG

 

The principle would be the same in DAX, except you would use LEFT() instead of Text.Start(), RIGHT() instead of Text.End, and '&' instead of Text.Combine.

 

Here is @nvprasad 's DAX solution converted to a Power Query column formula, if you want to push your transformations away from the data model (you should!):

= Text.Combine({Text.Start([postcode], (Text.Length([postcode]) -3)), Text.End([postcode], 3)}, " "))

 

 

Pete

 



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @AOD ,

 

In Power Query, you can add a new custom column and write code something like this:

 

 

 

=
if Text.Length([postcode]) = 6 
then Text.Combine({Text.Start([postcode], 3), Text.End([postcode], 3)}, " ")
else if Text.Length([postcode]) = 5 
then Text.Combine({Text.Start([postcode], 2), Text.End([postcode], 3)}, " ")
else "Another pattern")

 

 

 

 

This gives me the following output:

AOD.PNG

 

The principle would be the same in DAX, except you would use LEFT() instead of Text.Start(), RIGHT() instead of Text.End, and '&' instead of Text.Combine.

 

Here is @nvprasad 's DAX solution converted to a Power Query column formula, if you want to push your transformations away from the data model (you should!):

= Text.Combine({Text.Start([postcode], (Text.Length([postcode]) -3)), Text.End([postcode], 3)}, " "))

 

 

Pete

 



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




nvprasad
Solution Sage
Solution Sage

HI 

 

Yo can get by below code.

 

New Column = LEFT('Sample'[Code],LEN('Sample'[Code])-3)&" "& RIGHT('Sample'[Code],3)
 

Appreciate a Kudos! 🙂
If this helps and resolves the issue, please mark it as a Solution! 🙂

Regards,
N V Durga Prasad

Did I answer your question? Mark my post as a solution! Appreciate your Kudos.
Follow me on LinkedIn.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.