- 26 May 2021
- 5 Minutes to read
- Print
- DarkLight
Evaluate Expression Steps
- Updated on 26 May 2021
- 5 Minutes to read
- Print
- DarkLight
Overview
There are two expression steps; Evaluate Expression and Evaluate Dynamic Expression. The Evaluate Expression step is used to solve a defined algebraic expression. The step achieves this by automatically creating inputs for characters used to represent the numeric variables in the Expression. This can be helpful for people that work in fields such as banking or engineering, where they may need to evaluate a custom formula with data values from another step. The first example below demonstrates how to utilize an Evaluate Expression step to calculate the average of three test scores; the first exam, the midterm, and the final. The second example demonstrates how to utilize NCalc expressions in conjunction with an Evaluate Dynamic Expression step, to run a calculation.
Difference in Evaluate Expression and Evaluate Dynamic Expression Steps
The differences in the two evaluate expression steps lie in the different input mapping; the calculation code is the same for both. The Evaluate Expression step takes in the Expression solely as a constant. The Evaluate Dynamic Expression step allows for more dynamic mapping.
Evaluate Expression Mapping | Evaluate Dynamic Expression Mapping |
---|---|
Expression List
The chart below is a list of expressions that can be used in the Evaluate Expression and Evaluate Dynamic Expression steps to perform NCalc Functions. NCalc functions populate this list.
NAME | DESCRIPTION | USAGE | RESULT |
---|---|---|---|
Abs | Returns the absolute value of a specified number. | Abs(-1) | 1M |
Acos | Returns the angle whose cosine is the specified number. | Acos(1) | 0d |
Asin | Returns the angle whose sine is the specified number. | Asin(00 | 0d |
Atan | Returns the angle whose tangent is the specified number. | Atan(0) | 0d |
Ceiling | Returns the smallest integer greater than or equal to the specified number. | Ceiling(1.5) | 2d |
Cos | Returns the cosine of the specified angle. | Cos(0) | 1d |
Exp | Returns e raised to the specified power. | Exp(0) | 1d |
Floor | Returns the largest integer less than or equal to the specified number. | Floor(1.5) | 1d |
IEEERemainder | Returns the remainder resulting from the division of a specified number by another specified number. | IEEERemainder(3, 2) | -1d |
Log | Returns the logarithm of a specified number. | Log(1, 10) | 0d |
Log10 | Returns the base 10 logarithm of a specified number. | Log10(1) | 0d |
Max | Returns the larger of two specified numbers. | Max(1, 2) | 2 |
Min | Returns the smaller of two numbers. | Min(1, 2) | 1 |
Pow | Returns a specified number raised to the specified power. | Pow(3, 2) | 9d |
Sign | Returns a value indicating the sign of a number. | Sign(-10) | -1 |
Sin | Returns the sine of the specified angle. | Sin(0) | 0d |
Sqrt | Returns the square root of a specified number. | Sqrt(4) | 2d |
Tan | Returns the tangent of the specified angle. | Tan(0) | 0d |
Truncate | Calculates the integral part of a number. | Truncate(1.7) | 1 |
In | Returns whether an element is in a set of values. | in(1 + 1, 1, 2, 3) | true |
If | Returns a value based on a condition. | if(3 % 2 = 1, 'value is true', 'value is false') | 'value is true' |
Example A: Evaluate Expression
This example takes in user-defined values for each test value and averages them out using the Evaluate Expression step.
From a Designer Folder, select the Create Flow button from the bottom action bar. Select the default template and provide a name for the Flow, then select Create.
From the Steps panel, navigate to Data > Numbers and click and drag the Evaluate Expression step into the workspace; then, connect it to the Done path of the Start step.
Next, begin setting up the Expression. From the Properties tab of the Evaluate Expression step, input the following into the Expression box: (x+y+z)/3); this configuration will evaluate the sum of three variables and divide that sum by three. Afterward, connect the Done path of the step to the End step.
Next, add a Show Form step before the Evaluate Expression step and select Pick or Create Form from the Properties tab.
Name the Form, then select Create.
Begin creating the Form by dragging in a Button component from the Form Components tab and naming it "Submit".
Then, navigate to Form Components > Data and add three Number Box components on the right side of the Form; these will act as inputs for each test score. Name each Number box after the corresponding test.
Then, add a label for each test score.
After adding each input component, Save and Close the Form Designer to return to the Flow Designer.
Upon returning to the Flow Designer, attach the Submit path from the Form step to the Evaluate Expression step.
Next, select the Evaluate Expression step and map the test score outputs to their corresponding variable input via Select From Flow mapping.
Debug
After configuring the Inputs for the Evaluate Expression step, Debug the flow by selecting the 'Debug' button from the top toolbar of the Flow Designer.
Debug the Flow by inputting values for each test score and clicking Submit.
Next, right-click the Evaluate Expression step, then left-click the Execution and select View Input/Output Data.
The Data will show the three test score values as Inputs and the average of the 3 as the Output value.
Example B: Evaluate Dynamic Expression
The following example demonstrates how to use a Create Data with an Evaluate Dynamic Expression step to solve an algebraic expression.
- From a Designer Folder, select CREATE FLOW from the Global Action Bar, and CREATE a new Flow.
- From the Flow Designer, attach a Create Data step from the FAVORITE STEPS category of the Steps tab, to the Start step.
- From the Properties tab of the Create Data step, under DATA > Data to Create, and select the Show Editor link.
- From the Data Definitions window, Name the data "Expression" and select String from the Type dropdown. Under Input, by utilizing NCalc expressions (see the chart above), map an algebraic expression. Then click CLOSE to save the value and close the window.Mapping an ExpressionWhen defining an algebraic expression, NCalc expressions can be used in a similar manner to how they are typically used on a scientific or graphing calculator.
For this example, define the Expression as "(Sqrt(2+2))*10". In this case, the utilized NCalc expression, "Sqrt" is used to calculate the square root of the value in the parentheses. From Steps > Data > Numbers, attach an Evaluate Dynamic Expression step to the Done path of the Create Data step. Then connect the Done path of the Evaluate Dynamic Expression step to the End step.
From the Evaluate Dynamic Expression step's Properties, Select From Flow map Expression to its respective Input.
Additional Info on Mapping OptionsBy using an Evaluate Dynamic Expression step, users have the option to source the Expression Input in multiple dynamic ways. These ways include, Constant, Null, Ignore, Run Converter, Merge HTML Text, and Merge Plain Text options. This differs from being limited to only being able to define the Expression via Constant mapping.Save the Flow, then if desired, Close the Flow Designer.
Debug
- From the Flow Designer, select the Debug link from the top Action bar. Click FULL. Expression EvaluationUpon running the Flow, the Evaluate Dynamic Expression step calculates the outcome of the Dynamic Expression. The step accomplishes this by checking any evaluating any utilized NCalc expressions and solving the equation via standard algebraic order of operations.
After the Flow runs, select Evaluate Dynamic Expression 1 > Execution 1 > View Input/Output; verify that the step properly solved the Expression.