Sometimes strings in Power Automate need to be reformatted so that the first letter of each word is capitalized. This is know as “Proper Case”. There is no function built in to perform this common task. PowerApps does have this function so I expect it will arrive on Power Automate eventually.
In the mean time, here is an example flow and the required code to convert a string to Proper Case. The goal is to transform the sample string “this is a TEST” to “This Is A Test”
Example Proper Case Flow
Proper case is simple to achieve, take a look at this sample flow:
Explanation:
- The phrase to be transformed is added to a compose step.
- An apply to each is started and the input is a split expression which splits the phrase into an array.
- Each word is then passed into an expression which makes the first letter of the word uppercase and the remainder lower case.
- The final step of the flow uses a join expression to put the phrase back together again with spaces between each word.
The expression in the flow step “Capitalize each word” is:
if ( equals(length(item()),1), toupper(item()), concat(first(toupper(item())),toLower(substring(item(),1,sub(length(item()),1)))) )
Explanation of the expression:
- If the length of the word is only 1 letter, just output the uppercase representation of the word.
- If the word is longer than 1 character then uppercase the first letter of the word and lowercase the remainder.
I decided to write this up after someone asked how this could be done on the Power Automate community forums. He was following a blog post written by Elaiza Benitez that performs the same function.
My flow is mostly the same, but also works when one of the words has only one letter.
Hope this helps you out until the Power Automate team add a Proper Case function.
Andy Smith says
Fantastic article, we needed your example when we were dealing with processing addresses i.e. 7 tree close
You keep creating great articles on some of the nitty gritty aspects in using Power Automate with Data. Thanks
Paulie says
Thank you Andy. Lovely to get great feedback like this.
Martin says
I can’t seem to access outputs(‘Capitalize_each_word’) in the 3rd “Capitalized Phrase” section. When typing it in manually, it gives me an error that it’s not valid. Any ideas?
GWelch says
@Martin, The text to fit between the ” should be the name of the Compose action, replacing the spaces with underscores (_).
Daryl C. Valenzuela says
Thanks for sharing your ideas.
LK says
What about “This is a Test” if it started out as THIS is a TEST
Adrian says
Thank you so much for this code, I’m only facing some issues.
I’m trying to “Proper” the name, surname and role of a list of users, for the “Phrase” I’m calling the user profile to get these three items, I have a branch for each item, for example, the surname branch is like this:
1. Compose: outputs(‘Get_user_profile_(V2)’)?[‘body/surname’]
2. Apply to each: split(outputs(‘Surname’),”)
3. *Added the code you shared*
4. Capitalized phrase: join(outputs(‘Capitalize’),”)
Then after all branches run, all three items are concatenated in a SharePoint list action like this:
@{outputs(‘Last’)}, @{outputs(‘First’)} – @{outputs(‘Position’)}
The issue I’m having is all three items contain two or more words, I’m only getting the first word capitalized, for the surname, name and role. For example I’m getting “Doe deboe, John richard – Senior quality manager” instead of “Doe Deboe, John Richard – Senior Quality Manager”, any ideas what could be wrong?