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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Saxon10
Post Prodigy
Post Prodigy

Finding the space after the text

Hi,

 

I have item column that item column contain text & number. The item column conatin the sapce after the text(item).

I would like to know the no of spaces added after the text.

 

Capture.PNG

 

ItemDesired Result (No Space)
123450
12345  1
12345-001 1
456   3
345  2
124-pkds 1
124-001iv0
123450
4356780
2 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

Hi @Saxon10 

 

Download sample PBIX file

 

This will work in Power Query.  Create a new column with this code.  A full sample query is in the file above.

 

= Table.AddColumn(Source, "Num Spaces", each Text.Length([Item]) - Text.Length(Text.Trim([Item])))

 

countspace.png

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

PhilipTreacy
Super User
Super User

Hi @Saxon10 

Create a Calculated Column with this

NumSpaces = LEN([Item])-LEN(TRIM([Item]))

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

4 REPLIES 4
PhilipTreacy
Super User
Super User

Hi @Saxon10 

Create a Calculated Column with this

NumSpaces = LEN([Item])-LEN(TRIM([Item]))

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @Saxon10 

 

Download sample PBIX file

 

This will work in Power Query.  Create a new column with this code.  A full sample query is in the file above.

 

= Table.AddColumn(Source, "Num Spaces", each Text.Length([Item]) - Text.Length(Text.Trim([Item])))

 

countspace.png

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi, 

 

Thank you so much for your help and sorry for the late reply. Your solution is working very well. 

Thanks for your quick reply.

 

I would like to achieve the same result by using DAX Measure and New calculated column.

 

Can you please advise.

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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