Result
Understand how to create a user defined function to be used in the creation of calculated measures
Tutorial steps
- Create an Efficiency function - in the user defined section of the functions part of the Toolbox
- Replace the custom calculation - for boiler efficiency with the newly created function
- Re-deploy - the measure and re-confirm the results of the calculation
Functions
Select the "Tools" tab at the top of the Information Model. Expand the "Functions" folder.
Right-click on "User Defined" and click "New", "Function". Name the new function "Efficiency". Double-click on it to open its editor …
The function "Definition" is a standard Microsoft.NET C# static method. Don’t be scared of it, just type it out as shown above, or copy+paste from below:
public static double? Efficiency(double? Actual, double? Rating) { // Standard Efficiency Calculation return (Actual / Rating) * 100.0; }
Click the blue "tick" button to validate the "Definition". If there are any problems, Flow will provide an error message to explain what you have done wrong.
Using a Function in a Calculated Measure
Now that you have created your own User Defined Function for calculating Efficiency, let’s go back to the Calculated Measure you created for "Production Efficiency (%)" and edit its calculation expression to rather use your new function.
Open the "Production Efficiency (%)" measure and expand the "Retrieval" section. Undeploy the measure. Delete the expression. Drag the "Efficiency" function from the "Toolbox" into the expression editor.
Select the text "double Actual" and double-click the "Production (ton/hr)" measure. Flow will replace the selected text with the measure’s name and value property. Do the same for the "double Rating" and validate your new expression.
Redeploy your Calculated Measure.