cancel
Showing results for 
Search instead for 
Did you mean: 

Set text field data type as "Expression" to interpret mathematical formulas, add Calc() and Eval() Functions,

I would like to have a way for the user to be able to define mathematical expressions at runtime. 

 

For example, I would like to have the user be able to type: 

 

1 + 2 * ( 3 + sumOfSales) //sumOfSales is a variable

 

in a text box, and have it be treated as a formula, and calculate the result.

 

Text boxes would have a boolean setting to enable or disable the parsing of formulas. 

The formula would be available from the .Formula property. 

It would borrow from excel, and only interpret the input as a formula if the user starts typing with an equal sign. 
A literal equal sign can be added by starting with a single quote as well, just like Excel.

It would also be possible to parse text on other fields and display the results, using Calc() and Eval() formulas. 

 

Calc(param) - would take input from its parameter and attempt to parse it as a mathematical formula, allowing for references to other object properties, variables, and the Value() and Text() functions. It would not accept other PowerApps functions however.

 

Eval(param) - would be the fuller version, which would be able to parse the contents of its parameter as PowerApps code with all features. 

 

It should be possible to enable or disable the availability of the Eval() function on the project settings. The global admins should be able to block users from enabling the Eval() globally or per-user to prevent misuse or abuse.

Status: New
Comments
Crismogram
Regular Visitor

This is very helpful indeed. I have to use a flow with APIs Calculator like Bing Api or Math connectors  in order to calculate formulas that are in Text/String.

 

One more option is to create a PCF Control that has an eval function using JavaScript.

 

We don't have such function in Canvas Apps.

Using Value() will not work either since it is string.

 

Crismogram_0-1623864435007.png