Product(s): |
WaterGEMS, WaterCAD, HAMMER SewerCAD, SewerGEMS, StormCAD, CivilStorm |

Version(s): |
CONNECT Edition, V8i |

Area: |
Other |

# Problem

How is the “max” operator used with formula-derived user data extensions?

# Solution

The “Max” operator is available as a Math function when using the Real (Formula) data type while defining a user data extension (UDX).

The function can be used to compare the values in two fields for a element and report the one that is greater. Following is the generic format for the max function;

**System.Math.Max ([value_1] , [value_2])**

A typical example of this would be to find out the maximum invert elevation at a node;

**System.Math.Max ([GVFGravityNodeInvertResults_InvertInElevation1; Meters] , [GVFGravityNodeInvertResults_InvertInElevation2; Meters])**

The above formula compares the two invert elevations at a node and would return the maximum invert elevation.

It should be noted that the “Max” function accepts only two fields at a time for comparison. The option for entering multiple fields/values for comparison is currently unavailable. However, you can find out the maximum value in this case by looping the “Max” operator. The query statement would then look like this.

**System.Math.Max ([System.Math.Max ([value_1] , [value_2])] , [System.Math.Max ([value_3] , [value_4])])**

From the above statement the “Max” function is looped such that the two input parameters are “Max” queries themselves for the actual values to be compared.

Like the example shown above, for multiple invert elevations (more than two pipes entering a node) the query statement would be like this;

**System.Math.Max (System.Math.Max ([GVFGravityNodeInvertResults_InvertInElevation1; Meters] , [GVFGravityNodeInvertResults_InvertInElevation2; Meters]) , System.Math.Max ([GVFGravityNodeInvertResults_InvertInElevation1; Meters] , [GVFGravityNodeInvertResults_InvertInElevation2; Meters]))**

This would return the maximum invert elevation from the four invert elevations incoming the node.

It should be noted that this approach would work for an even number of values in the range (viz. 2, 4, 6 etc.) since the “Max” functions can take two values for comparison.

Related Enhancement # 877689 (Add a built in Elevation (Max Invert In) field)

# See Also

How do you create an IF / THEN / ELSE statements using Formula derived user data extensions?