The Value function in Power Apps is used to convert a text string that represents a number into a numeric value. This function is essential when dealing with numeric data that is entered as text, such as values from text input controls.
PowerApps – Value() function Syntax
- Text: The text string to convert to a number.
Notes:
- Input Validation: Ensure that the text input is a valid number to avoid errors when using the Value function. Use functions like IsNumeric for validation.
- Error Handling: Handle potential errors gracefully by providing feedback to the user if the input is not a valid number.
PowerApps - Basic Conversion from text to number
Suppose you have a text input control where users enter a number, and you want to convert this text to a numeric value for calculations.
When a user enters a number in the TextInput1 control, the label will display the numeric value of the entered text.
PowerApps - Perform Calculations on numbers added in textbox control
Suppose you want to calculate the total price including tax based on user inputs for price and tax rate.
- Add a Text Input Control for Price:
- Insert a Text Input control named PriceInput.
- Set the HintText property to "Enter price".
- Add a Text Input Control for Tax Rate:
- Insert a Text Input control named TaxRateInput.
- Set the HintText property to "Enter tax rate".
- Add a Button Control to Perform the Calculation:
- Insert a Button control named CalculateButton.
- Set the Text property of the Button to "Calculate".
- Add a Label Control to Display the Total Price:
- Insert a Label control.
- Set the Text property of the Label to:
With(
{ Price: Value(PriceInput.Text), TaxRate: Value(TaxRateInput.Text) },
"Total Price: $" & Text(Price + (Price * TaxRate), "[$-en-US]0.00")
)
When the user enters values in the PriceInput and TaxRateInput controls and clicks the "Calculate" button, the label will display the calculated total price including tax, formatted to two decimal places.
PowerApps - Conditional Logic with Numeric Conversion
Suppose you want to determine if a user-entered number is positive, negative, or zero.
- Add a Text Input Control:
- Insert a Text Input control named NumberInput.
- Set the HintText property to "Enter a number".
- Add a Label Control to Display the Result:
- Insert a Label control.
- Set the Text property of the Label to:
With(
{ Num: Value(NumberInput.Text) },
If(Num > 0, "Positive", If(Num < 0, "Negative", "Zero"))
)
This will evaluate the entered number and display "Positive", "Negative", or "Zero" based on the value.
PowerApps – Use numeric value in Data Source Filtering
Suppose you have a data source named Products with a numeric field Price, and you want to filter the products based on a price entered by the user.
- Add a Text Input Control for Price Filter:
- Insert a Text Input control named PriceFilterInput.
- Set the HintText property to "Enter max price".
- Add a Gallery Control to Display Filtered Products:
- Insert a Gallery control named ProductGallery.
- Set the Items property of the gallery to:
Filter(Products, Price <= Value(PriceFilterInput.Text))
When the user enters a price in the PriceFilterInput control, the gallery will display products with prices less than or equal to the entered value.