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
kfschaefer
Helper IV
Helper IV

Trim first letter of each word in a string

I am looking for the best approach to Trim the First letter of each text string to come up with an abbreviation.

 

Example.

 

Supply Chain and Mgmt.  = SCM

Electric Light & Power = ELP

Joe's Power Source Company =  JPSC

 

What functions should I use?  This is what I have so far, however, it is asking for a paran and =0, or =1,Capture.PNG

 

IF(len([Org])-len(SUBSTITUTE([Org]," ",""))=0,left([Org],1),

if(len([Org])-len(SUBSTITUTE([Org]," ",""))=1, left([Org],1)

&mid([Org],find(" ",[Org])+1,1),left([Org],1)&mid([Org],find(" ",[Org])+1,1)&mid([Org],find(" ",[Org],find(" ",[Org])+1)+1,1)))

Thanks,

 

Karen

1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

Hi @kfschaefer,

Based on my test, you could refer to below steps:

Sample data:

1.PNG

Split the [Text] column by space in query editor:

2.PNG

Extracted First Characters:

3.PNG

Apply it and create a calculated column:

Column = var a=IF(UNICODE('Table1'[Text.1])>=65&&UNICODE('Table1'[Text.1])<=90,[Text.1],BLANK())
        var b=IF(UNICODE('Table1'[Text.2])>=65&&UNICODE('Table1'[Text.2])<=90,[Text.2],BLANK())
        var c=IF(UNICODE('Table1'[Text.3])>=65&&UNICODE('Table1'[Text.3])<=90,[Text.3],BLANK())
        var d=IF(UNICODE('Table1'[Text.4])>=65&&UNICODE('Table1'[Text.4])<=90,[Text.4],BLANK())
        return CONCATENATE(a,CONCATENATE(b,CONCATENATE(c,d)))

Result:

1.PNG

You could also download the pbix to have a view:

https://www.dropbox.com/s/cfmvbv4kyl94thq/Trim%20first%20letter%20of%20each%20word%20in%20a%20string...

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
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

4 REPLIES 4
BettinaEK
Regular Visitor

Hi @kfschaefer 

 

An alternative, and more human-readable, solution using Power Query M is a single line of code (nested for readability):

 

Text.Remove(

   Text.Replace(

      Text.Proper(

         Text.Remove(

            Text.Trim(

               Text.Clean([Org])

            ),

         {"'"}) //remove those characters interpreted as delimiters in Text.Proper()

      ),

   " And "," "),

{"a".."z","0".."9","(",")"," ",",",".","&","£"})

 

The Power of M lies in it's human readability, which not only does not require encyclopaedic knowledge of ASCII or Unicode, but also automatically makes it much easier to customise -- all data sets are wonky in different and creative ways.

 

Your source data will drive the functions you use and the order in which you use them. Some of the steps in this example can be reordered or repeated to suit your data source.

 

Read more here: The Power of M... and don't forget the function reference library

 

BEK

redefining the box

v-danhe-msft
Employee
Employee

Hi @kfschaefer,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Employee
Employee

Hi @kfschaefer,

Based on my test, you could refer to below steps:

Sample data:

1.PNG

Split the [Text] column by space in query editor:

2.PNG

Extracted First Characters:

3.PNG

Apply it and create a calculated column:

Column = var a=IF(UNICODE('Table1'[Text.1])>=65&&UNICODE('Table1'[Text.1])<=90,[Text.1],BLANK())
        var b=IF(UNICODE('Table1'[Text.2])>=65&&UNICODE('Table1'[Text.2])<=90,[Text.2],BLANK())
        var c=IF(UNICODE('Table1'[Text.3])>=65&&UNICODE('Table1'[Text.3])<=90,[Text.3],BLANK())
        var d=IF(UNICODE('Table1'[Text.4])>=65&&UNICODE('Table1'[Text.4])<=90,[Text.4],BLANK())
        return CONCATENATE(a,CONCATENATE(b,CONCATENATE(c,d)))

Result:

1.PNG

You could also download the pbix to have a view:

https://www.dropbox.com/s/cfmvbv4kyl94thq/Trim%20first%20letter%20of%20each%20word%20in%20a%20string...

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

In the table, if the name or the text string you want to format is in one column, I could think of one work around where you could extract the text before or after the delimiter/s. This will create separate columns for each word in the string. Then extract the first character for each word. Finally, combine the extracted first letters. It may seem like a long process, but it is actually easy to achieve.

 

Hope this helps!

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.