Mid

How to Use the Power Fx Mid  Function in Power Apps

What is the Power Fx Mid Function?

The Power Fx mid function is used to extract a substring from a text string starting at a specified position and with a specified length. It takes three arguments:

– The text string to extract from

– The starting position of the substring

– The length of the substring to extract

The syntax for the Power Fx mid function is as follows:


Mid(Text, Start, Length)


How to Use the Power Fx Mid Function

To use the Power Fx mid function in Power Apps, follow these steps:

1. Open the Power Apps Studio and create a new canvas app.

2. Add a Text Input control to the canvas. This control will be used to enter the input string.

3. Add a Label control to the canvas. This control will be used to display the output of the mid function.

4. Select the Text Input control and open the Properties pane.

5. In the Default property, enter the input string that you want to extract a substring from.

6. Select the Label control and open the Properties pane.

7. In the Text property, enter the following formula:


Mid(TextInput1.Text, 3, 5)


This formula extracts a substring from the input string starting at position 3 and with a length of 5.

8. Save and preview the app.

9. Enter a string in the Text Input control and see the output displayed in the Label control.

Using Variables with the Power Fx Mid Function

You can also use variables with the Power Fx mid function to extract substrings from dynamic data sources. To do this, follow these steps:

1. Add a Button control to the canvas.

2. Select the Button control and open the Properties pane.

3. In the OnSelect property, enter the following formula:


ClearCollect(

MyCollection,

{

Text: “This is an example string”

}

);

UpdateContext({ MyVar: First(MyCollection).Text });

UpdateContext({ MySubstring: Mid(MyVar, 6, 2) })


This formula creates a collection with a single record, sets a variable to the value of the Text field in the record, and then extracts a substring from the variable starting at position 6 and with a length of 2.

4. Save and preview the app.

5. Click the Button control to see the output displayed in a Label control.

The Power Fx mid function is a powerful tool in Power Apps that allows users to extract substrings from text strings. By following the steps outlined in this article, you can use the Power Fx mid function to transform data in your Power Apps.

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