Abs

How to Use the Power Fx AbsĀ  Function in Power Apps

Understanding the Power Fx Abs Function

The Power Fx Abs function is a mathematical function that returns the absolute value of a number. The absolute value of a number is the distance between the number and zero on a number line. It is always a positive value, regardless of whether the input number is positive or negative. For example, the absolute value of -5 is 5, and the absolute value of 5 is also 5.

Using the Power Fx Abs Function in Power Apps

To use the Power Fx Abs function in Power Apps, you need to understand its syntax. The function takes one argument, which is the number you want to find the absolute value of. The syntax for the function is as follows:


Abs(Number)


Where `Number` is the input number you want to find the absolute value of. For example, to find the absolute value of -5, you would use the following formula:


Abs(-5)


This would return the value 5.

Examples of Using the Power Fx Abs Function

The Power Fx Abs function can be used in various scenarios in Power Apps. Here are some examples of how you can use this function in your apps:

Example 1: Calculating the Difference Between Two Numbers

Suppose you have two numbers and you want to find the difference between them. You can use the Power Fx Abs function to get the absolute value of the difference between the two numbers. Here’s how you can do it:

1. Create two input fields for the two numbers you want to find the difference of.

2. Add a button to the app, and set its OnSelect property to the following formula:


ClearCollect(Result, {Difference: Abs(Number1 - Number2)})


Where `Number1` and `Number2` are the names of the input fields for the two numbers, and `Result` is the name of a collection that will store the result.

3. Add a label to the app, and set its Text property to the following formula:


Result.Difference


This will display the absolute value of the difference between the two numbers.

Example 2: Finding the Distance Between Two Points

Suppose you have two points on a coordinate plane and you want to find the distance between them. You can use the Power Fx Abs function to get the absolute value of the difference between the x-coordinates and y-coordinates of the two points. Here’s how you can do it:

1. Create four input fields for the two x-coordinates and two y-coordinates.

2. Add a button to the app, and set its OnSelect property to the following formula:


ClearCollect(Result, {Distance: Sqrt(Abs(X2 - X1)^2 + Abs(Y2 - Y1)^2)})


Where `X1`, `X2`, `Y1`, and `Y2` are the names of the input fields for the coordinates, and `Result` is the name of a collection that will store the result.

3. Add a label to the app, and set its Text property to the following formula:


Result.Distance


This will display the distance between the two points.

The Power Fx Abs function is a useful function in Power Apps that can simplify complex calculations and data manipulation. Understanding its syntax and how to use it in different scenarios can help you create more effective and efficient apps. We hope this article has provided you with the knowledge you need to make the most of the Power Fx Abs function in your app-building experience.

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