It is a bit baffling, but as of 2023 and the time of this article, Power Automate still doesn’t have toProper() function. There are multiple ways to work around that, to name a few: Select action, Apply to each (loop) action, Azure Automate (PowerShell in the cloud). Personally, I would use Azure Automation (especially when formatting something more than people names) but that would be a more complex approach. The method below works in a pinch.
You may ask why one would need to format names to a proper case. Well, when you are dealing with older databases, it’s possible the data is formatted with UPPERCASE.
Pros:
- simple and works within Select actions;
- very fast and doesn’t require looping or Azure Automation;
- handles “up to” triple barrel names;
- works well in a real life scenario.
Cons:
- only handles “up to” triple barrel names (anything more complex will not be properly converted);
- a bit ugly and is pretty much hardcoding.
1) Initialize variable action – varFirstNames variable (Array type). Value:
[ "PAUL", "J", "GAIUS JULIUS CEASAR", "AMELIA ROSE", "ELLIE-MAY", "ELLA KISSI-DEBRA", "ANTONY-CHARLES-ROBERT" ]
2) Select action. From:
variables('varFirstNames')
Select:
toLower(item())
3) Select action. From:
body('toLower')
Select:
if(
equals(item(),''),
'',
if(
equals(length(split(item(),' ')),2),
concat(
if(
equals(length(split(split(item(),' ')[0],'-')),2),
concat(
if(equals(length(split(split(item(),' ')[0],'-')[0]),1),first(toupper(split(split(item(),' ')[0],'-')[0])),concat(first(toupper(split(split(item(),' ')[0],'-')[0])),substring(split(split(item(),' ')[0],'-')[0],1,sub(length(split(split(item(),' ')[0],'-')[0]),1)))),
'-',
if(equals(length(split(split(item(),' ')[0],'-')[1]),1),first(toupper(split(split(item(),' ')[0],'-')[1])),concat(first(toupper(split(split(item(),' ')[0],'-')[1])),substring(split(split(item(),' ')[0],'-')[1],1,sub(length(split(split(item(),' ')[0],'-')[1]),1))))
),
if(equals(length(split(item(),' ')[0]),1),first(toupper(split(item(),' ')[0])),concat(first(toupper(split(item(),' ')[0])),substring(split(item(),' ')[0],1,sub(length(split(item(),' ')[0]),1))))
),
' ',
if(
equals(length(split(split(item(),' ')[1],'-')),2),
concat(
if(equals(length(split(split(item(),' ')[1],'-')[0]),1),first(toupper(split(split(item(),' ')[1],'-')[0])),concat(first(toupper(split(split(item(),' ')[1],'-')[0])),substring(split(split(item(),' ')[1],'-')[0],1,sub(length(split(split(item(),' ')[1],'-')[0]),1)))),
'-',
if(equals(length(split(split(item(),' ')[1],'-')[1]),1),first(toupper(split(split(item(),' ')[1],'-')[1])),concat(first(toupper(split(split(item(),' ')[1],'-')[1])),substring(split(split(item(),' ')[1],'-')[1],1,sub(length(split(split(item(),' ')[1],'-')[1]),1))))
),
if(equals(length(split(item(),' ')[1]),1),first(toupper(split(item(),' ')[1])),concat(first(toupper(split(item(),' ')[1])),substring(split(item(),' ')[1],1,sub(length(split(item(),' ')[1]),1))))
)
),
if(
equals(length(split(item(),' ')),3),
concat(
if(equals(length(split(item(),' ')[0]),1),first(toupper(split(item(),' ')[0])),concat(first(toupper(split(item(),' ')[0])),substring(split(item(),' ')[0],1,sub(length(split(item(),' ')[0]),1)))),
' ',
if(equals(length(split(item(),' ')[1]),1),first(toupper(split(item(),' ')[1])),concat(first(toupper(split(item(),' ')[1])),substring(split(item(),' ')[1],1,sub(length(split(item(),' ')[1]),1)))),
' ',
if(equals(length(split(item(),' ')[2]),1),first(toupper(split(item(),' ')[2])),concat(first(toupper(split(item(),' ')[2])),substring(split(item(),' ')[2],1,sub(length(split(item(),' ')[2]),1))))
),
if(
equals(length(split(item(),'-')),2),
concat(
if(equals(length(split(item(),'-')[0]),1),first(toupper(split(item(),'-')[0])),concat(first(toupper(split(item(),'-')[0])),substring(split(item(),'-')[0],1,sub(length(split(item(),'-')[0]),1)))),
'-',
if(equals(length(split(item(),'-')[1]),1),first(toupper(split(item(),'-')[1])),concat(first(toupper(split(item(),'-')[1])),substring(split(item(),'-')[1],1,sub(length(split(item(),'-')[1]),1))))
),
if(
equals(length(split(item(),'-')),3),
concat(
if(equals(length(split(item(),'-')[0]),1),first(toupper(split(item(),'-')[0])),concat(first(toupper(split(item(),'-')[0])),substring(split(item(),'-')[0],1,sub(length(split(item(),'-')[0]),1)))),
'-',
if(equals(length(split(item(),'-')[1]),1),first(toupper(split(item(),'-')[1])),concat(first(toupper(split(item(),'-')[1])),substring(split(item(),'-')[1],1,sub(length(split(item(),'-')[1]),1)))),
'-',
if(equals(length(split(item(),'-')[2]),1),first(toupper(split(item(),'-')[2])),concat(first(toupper(split(item(),'-')[2])),substring(split(item(),'-')[2],1,sub(length(split(item(),'-')[2]),1))))
),
if(
equals(length(item()),1),
toUpper(item()),
concat(first(toupper(split(item(),' ')[0])),substring(split(item(),' ')[0],1,sub(length(split(item(),' ')[0]),1)))
)
)
)
)
)
)
RESULT
[ "Paul", "J", "Gaius Julius Ceasar", "Amelia Rose", "Ellie-May", "Ella Kissi-Debra", "Antony-Charles-Robert" ]
