Topic: DMD0093

Help File Version: 2.9.4.37

COUNTIF - Count If


This instruction can only be used in the Expression parameter of the Calculate Expression (MATH) instruction.

 

The Count If (COUNTIFxx) math functions count the number of locations in the specified range that match the specified value by making the comparison by the function name. There are six variants of the CountIf math function, and all six have the following three parameters:

 

The first parameter specifies the comparison value. This can be any expression parameter, including any constant value, any readable numeric location, any readable bit location, any Math function, or any combination of these with Math operators.

 

The second parameter specifies the first location in the range of locations to compare against. This can be any readable numeric data-block location, or any readable bit data-block location.

 

The third parameter specifies the number of contiguous locations that will be compared against. This can be any expression parameter, including any constant value, any readable numeric location, any readable bit location, any Math function, or any combination of these with Math operators.

If the third parameter is 0, the result will be 0, and Argument Out of Range (ST132) will be ON.

 

If the third parameter exceeds the size of the specified data block, the result will only include the values up through the last location in the block, and Argument Out of Range (ST132) will be ON. For example, assume the block of WX locations has a range of WX0 to WX255. The result of COUNTIFEQ(45, WX250, 10) would only include the values in WX250 through WX255, and Argument Out of Range (ST132) will be ON.


The following are the 6 variants of the Count If math function:


COUNTIFEQ - Count If Equal to Expression

 

In the example above, D0 will contain the number of locations in the range of D100 through D109 that contain a value that is equal to 45.


COUNTIFNE - Count If Not Equal to Expression

 

In the example above, D0 will contain the number of locations in the range of D100 through D109 that contain a value that is not equal to 45.


COUNTIFLT - Count If Less Than Expression

 

In the example above, D0 will contain the number of locations in the range of D100 through D109 that contain a value that is less than 45.


COUNTIFLE - Count If Less Than or Equal to Expression

 

In the example above, D0 will contain the number of locations in the range of D100 through D109 that contain a value that is less than or equal to 45.


COUNTIFGT - Count If Greater Than Expression

 

In the example above, D0 will contain the number of locations in the range of D100 through D109 that contain a value that is greater than 45.


COUNTIFGE - Count If Greater Than or Equal to Expression

 

In the example above, D0 will contain the number of locations in the range of D100 through D109 that contain a value that is greater than or equal to 45.


See Also:

MATH - Calculate Expression

 

IF - If / Else Expression

 

SUMIF - Sum If

 

COUNTIF - Count If

 


Rung Example: