$-Strings: A Better Way To Concatenate Text Strings In Power Apps
$-Strings: A Better Way To Concatenate Text Strings In Power Apps Posted by - Matthew Devaney on - April 10, 2022 49 Comments An awesome new way to concatena...
- Published
- Reading time
- 7 min read
Before you start
Is this guide for you?
- Best entry point
- Power Apps
- Time investment
- 7 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/strings-a-better-way-to-concatenate-text-strings-in-power-apps/. Author: Matthew Devaney.
$-Strings: A Better Way To Concatenate Text Strings In Power Apps Posted by - Matthew Devaney on - April 10, 2022 49 Comments
An awesome new way to concatenate text strings in Power Apps has arrived with $-Strings. Placing the $ symbol in front of any text string now defines it as an $-String. Then you can write any function, expression of variable inside a within a pair of curly braces { } inside the text string. I love this syntax and I can’t wait to share it with the world. In this article I will show you how to use $-Strings to concatenate a text string in Power Apps. Table Of Contents • < a style = "font-size: revert;"
href = "#The-New-Way-To-Concatenate-Text-With-$-Strings" > The New Way To Concatenate Text With $-Strings </ a > • < a style = "font-size: revert;"
href = "#$-String-Usage-Examples" > $-String Usage Examples </ a > < strong > ⚬ </ strong > < a style = "font-size: revert;"
href = "#Referencing-Controls" > Referencing Controls </ a > < strong > ⚬ </ strong > < a style = "font-size: revert;"
href = "#Reading-Variable-Values" > Reading Variable Values </ a > < strong > ⚬ </ strong > < a style = "font-size: revert;"
href = "#Math-Expressions" > Math Expressions </ a > < strong > ⚬ </ strong > < a style = "font-size: revert;"
href = "#Concat-Function" > Concat Function </ a > < strong > ⚬ </ strong > < a style = "font-size: revert;"
href = "#Error-Handling" > Error Handling </ a > • < a style = "font-size: revert;"
href = "#Other $-String Details" > Other $-String Details </ a > < strong > ⚬ </ strong > < a style = "font-size: revert;"
href = "#Curly-Braces" > Curly Braces </ a > < strong > ⚬ </ strong > < a style = "font-size: revert;"
href = "#Quotation-Marks" > Quotation Marks </ a > Code language: HTML, XML ( xml )
The “Old Way” To Concatenate Text Strings In Power Apps
A common thing we want to do in Power Apps is show the app user a welcome message with their name and the current date.
Hello, Matthew Devaney. The current date is 4/10/2022.
The message is a made up of two elements: text used to define the standard greeting users will see and functions used to obtain their name and the current date. To display these elements as a single message we can use the CONCATENATE function to join them together. Each section of text or function is a supplied as a new argument separated by a comma. It works, but the code itself is somewhat verbose and not very readable. Concatenate( "Hello my name is" , User().FullName, ". The current date is" , Today(), "." ) Code language: JavaScript ( javascript )
Another way to join multiple text strings and functions together is with & operator. Instead of writing a CONCATENATE function we simply write an & symbol between each section just like Microsoft Excel. This more readable during a code review but I find it a pain to type the extra & symbol and quotation mark between each segement.
"Hello my name is" & User().FullName & ". The current date is" & Today() & "." Code language: JavaScript ( javascript ) The New Way To Concatenate Text With $ Strings
My preferred way to concatenate text strings in Power Apps is by using the new $-String syntax. To do this we put a dollar sign ($) in front the text string’s quotation marks and use curly braces {} to denote the parts of it which are expressions – functions, formulas or variables that might change. The official term for this technique is string interpolation and it is found in many other programming languages.
$ "Hello {User().FullName}. The current date is {Today()}." Code language: JavaScript ( javascript )
I enjoy $-Strings because they require the least amount of syntax to write and my code is easily readable when reviewing it. $ String Usage Examples
Let’s take a look at few more examples of how we can use $-Strings to concatenate text in Power Apps. Referencing Controls
We can join the text from a text input and selected date from a date picker to other text strings like this:
$ "Hello {txt_Username.Text}. The current date is {dte_CurrentDate.SelectedDate}." Code language: JavaScript ( javascript ) The result looks like this: Reading Variable Values
We could also choose to store the result some functions in variables and use those variables inside the $-String. // set variables elsewhere in the code Set (varUsername, User().FullName); Set (varToday, Today());
// use this value in the Text property of a label
$ "Hello {varUsername}. The current date is {varToday}." Code language: JavaScript ( javascript ) Math Expressions
Writing mathematical expressions inside of $-strings is an interesting use case. Anything inside the curly braces can be a formula so we can directly write 4 * 3 inside the text string to find the result of 12. $ "{4} multiplied by {3} equals {4*3}" Code language: JavaScript ( javascript )
Here’s a similar example of how we could multiply two values found within text inputs and show the result
$ "{txt_Number1.Text} multiplied by {txt_Number2.Text} equals {Value(txt_Number1.Text) * Value(txt_Number2.Text)}" Code language: JavaScript ( javascript ) Concat Function
The $-String is quite valuable when using the CONCAT function . CONCAT joins the result of a formula applied to all records in a table and outputs a single text string. In this example I have created a table holding the numbers 1-through-5 and want to know their squares .
Concat(Sequence( 5 ), $ "{Value} squared equals {Value * Value}.{Char(13)}" ) Code language: JavaScript ( javascript ) The resulting text string looks this:
1 squared equals 1 2 squared equals 4 3 squared equals 9 4 squared equals 16 5 squared equals 25 Error Handling
One final use case for $-Strings is error-handling . We can place the following code within the OnError property of an app to show the developer a helpful error message.
Notify( $ "Error was observed at {Error.Observed}: {Error.Message}" , NotificationType.Error ) Code language: JavaScript ( javascript )
The resulting error message would look something this. This specific error message is saying the app cannot perform division by zero and the value entered in the text input txt_Number is causing the problem.
Error was observed at txt_Number: Cannot divide by zero Code language: JavaScript ( javascript ) Other $-String Details
When concatenating text with Power Apps $-String notation you might have the following difficulties. Curly Braces
Curly braces are rarely needed inside text strings but what if we wanted to display a message like this?
This is how you write curly braces {} in Power Apps $-Strings.
We can show curly braces inside of an $-String by placing one pair of curly braces inside another.
$ "This is how you write curly braces {{}} in Power Apps $-Strings." Code language: JavaScript ( javascript )
What if a word needed to be shown within curly braces?
I can also write words inside curly braces {like this } Code language: JavaScript ( javascript )
Again, we simply have to write two-pairs of curly braces with the word in the middle.
$ "I can also write words inside curly braces {{like this}}" Code language: JavaScript ( javascript ) Quotation Marks
Quotation marks are another challenge because they are used to identify text strings. What if we wanted to write the sentence below?
The English word "Hello" has the same meaning as the French word "Bonjour" Code language: JavaScript ( javascript )
By writing 3 sets of quotation marks we can tell Power Apps to display a single-set of quotation marks surrounding the words “Hello” and “Bonjour”. $ "The English word {" "" Hello ""
"} has the same meaning as the French word {" "" Bonjour "" "}" Code language: JavaScript ( javascript ) Did You Enjoy This Article? 😺
Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?
If you have any questions about $-Strings: A Better Way To Concatenate Text Strings In Power Apps please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney M365 Copilot Power Apps
How To Create Copilot Custom UI Widgets In Power Apps
Tagged
Power Apps
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 learning notes.
Keep learning Microsoft 365
Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.
Continue learning
Related tutorials
Related questions
Related comparisons
Next action