StartsWith

How to Use the Power Fx StartsWith  Function in Power Apps

What is the StartsWith function?

The StartsWith function is a text function that checks if a string starts with a specific set of characters. It’s commonly used to check if a string starts with a particular word, phrase, or prefix. The syntax for the StartsWith function is as follows:


StartsWith(Text, Prefix)


The Text parameter is the string you want to search in, and the Prefix parameter is the string you want to search for. The function returns a Boolean value (true or false) indicating whether the Text string starts with the Prefix string.

How to use the StartsWith function in Power Apps

To use the StartsWith function in Power Apps, you'll need to add it to a formula. You can do this by selecting the control or data source you want to apply the formula to, and then clicking on the function button in the formula bar. This will open the formula bar, where you can enter your formula.

Here's an example of how to use the StartsWith function to search for a specific prefix in a text box:

1. Add a text input control to your app.

2. Set the Default property of the text input control to "Type a word or phrase".

3. Add a label control to your app.

4. Set the Text property of the label control to the following formula:


If(StartsWith(TextInput1.Text, “Hello”), “Text starts with Hello”, “Text does not start with Hello”)


This formula uses the StartsWith function to check if the text in the text input control starts with the word "Hello". If it does, the label control will display the text "Text starts with Hello". If it doesn't, the label control will display the text "Text does not start with Hello".

You can also use the StartsWith function to filter data in a gallery control. Here's an example of how to use the StartsWith function to filter a gallery based on a specific prefix:

1. Add a gallery control to your app.

2. Set the Items property of the gallery control to a data source (e.g., SharePoint list, Excel table, etc.).

3. Add a text input control to your app.

4. Set the Default property of the text input control to "Type a word or phrase".

5. Set the Items property of the gallery control to the following formula:


Filter(DataSource, StartsWith(Title, TextInput1.Text))


This formula uses the StartsWith function to filter the data in the gallery based on the text entered in the text input control. It returns only the items where the Title field starts with the entered text.

The StartsWith function is a simple but powerful tool for searching for specific strings in Power Apps. By using it in your formulas, you can easily filter data and create dynamic user interfaces. Whether you're a beginner or an advanced user, mastering the StartsWith function will help you take your Power Apps skills to the next level.

Power Apps Training Courses by G Com Solutions (0800 998 9248)