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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
suebayes
Resolver I
Resolver I

Text Transformations in Power Query

I want to be able to capitalise only the first word in any sentence within a column.  Note there can be many sentences within one column.

What data looks like

Name       Answer

SueThis is great.  Fantastic news.
JonTHIS IS GREAT.  I really like this.  Silly capitals.
JoeNot just one sentence.  THERE COULD BE LOTS.

 

What it should look like

Name    Answer

SueThis is great.  Fantastic news.
JonThis is great.  I really like this.  Silly capitals.
JoeNot just one sentence.  There could be lots.
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY3LCsIwFER/Zci69B98RFspLTRxFboI4aLRkIi5Rfx7bzfCrIZzZpxTZiXVKHuPFZLbmzy3wMln9pVjQKZPbdXSOHUpeSO73kBynvXOCtlDlJS+SPFJYNmR0sStCf4V2ae/vh2NhfFYK6NkQqXMlAOJYTs9axym63DEXmOYrBFt+QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Answer = _t]),
    #"Lowercased Text" = Table.TransformColumns(Source,{{"Answer", Text.Lower, type text}}),
    #"Added Custom" = Table.AddColumn(#"Lowercased Text", "Custom", each let x = Text.Split([Answer], ". ")
in List.Transform(x, each Text.Upper(Text.Start(Text.Trim(_),1)) & Text.End(Text.Trim(_), Text.Length(Text.Trim(_))-1)))
in
    #"Added Custom"

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY3LCsIwFER/Zci69B98RFspLTRxFboI4aLRkIi5Rfx7bzfCrIZzZpxTZiXVKHuPFZLbmzy3wMln9pVjQKZPbdXSOHUpeSO73kBynvXOCtlDlJS+SPFJYNmR0sStCf4V2ae/vh2NhfFYK6NkQqXMlAOJYTs9axym63DEXmOYrBFt+QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Answer = _t]),
    #"Lowercased Text" = Table.TransformColumns(Source,{{"Answer", Text.Lower, type text}}),
    #"Added Custom" = Table.AddColumn(#"Lowercased Text", "Custom", each let x = Text.Split([Answer], ". ")
in List.Transform(x, each Text.Upper(Text.Start(Text.Trim(_),1)) & Text.End(Text.Trim(_), Text.Length(Text.Trim(_))-1)))
in
    #"Added Custom"

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks Pat, I sort of thought that might be the way to go but couldn't wrap my head around the syntax required to make it do it.  That's very elegant thank you @mahoneypat 

Greg_Deckler
Community Champion
Community Champion

@suebayes Not aware of anything for this. There is Text.Proper and Text.Upper but they do not do what you are asking. You could try adding column from examples and see if it can figure it out. @edhans @ImkeF 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler for replying, much appreciated.  

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors