Skip to content
Home » Substitute function in Power Apps

Substitute function in Power Apps

The Substitute function in Power Apps is used to replace occurrences of specific text within a string with provided value. It’s useful when you want to change part of a string or clean up a string by replacing unwanted characters or words.




Syntax:

Substitute(Text, OldText, NewText, [InstanceNumber])
  • Text: The original string in which you want to replace text.
  • OldText: The text you want to find and replace.
  • NewText: The text that will replace OldText.
  • InstanceNumber (optional): Specifies which instance of OldText to replace. If omitted, all instances will be replaced.

Example of using substitue function

Replace the occurence of string

Replace the “Sales” with “Monthly Sales (in $)” in a string: “Sales Data”.

Following formula will find for the word “Sales” in the original string “Sales Data” and replace “Sales” with “Monthly Sales (in $)” and returns the string“Monthly Sales (in $) Data”.

Substitute(
    "Sales Data",
    "Sales",
    "Monthly Sales (in $)"
)

 

Replace a specific instance

You can replace a specific instance of a string within another string using the Substitute function for this you need to provide the fourth argument of the Substitute function, called InstanceNumber.

This argument specifies which occurrence (or instance) of the string you want to replace.

To replace only the second occurrence of  “Power” with “Microsoft Power” in a string “Hello, Power User. Welcome to the Power BI community !”.

Following formula replace the second occurenece of string “Power” with “Microsoft Power” within a string “Hello, Power User. Welcome to the Power BI community !”.

Substitute(
    "Hello, Power User. Welcome to the Power BI community !",
    "Power",
    "Microsoft Power",
    2
)

It returns the string “Hello, Power User. Welcome to the Microsoft Power BI community !”




 

 

Also Read..

Loading

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SQL BI Tutorials

Subscribe now to keep reading and get access to the full archive.

Continue reading