This is an old revision of the document!
Count
Counts the number of records, rows or times where a condition is true.
Parameters
| Name | Default | Meaning |
|---|---|---|
| name | The name of the value to be written to the frame | |
| where | A Substitutable condition - the count increases by 1 for every row that matches the rule. | |
| when | A Substitutable condition - the count increases by 1 for every the the rule becomes 'true' | |
| changesin | The name of a table column - the count increases by 1 for every time the value changes | |
| ignoring | Values to ignore when 'changesin' is specified | |
| up | Only counts increases in value | |
| down | Only counts decreases in value | |
| reset | Set to 'hard' to indicate that 'up' and 'down' counting should expect the counter to drop back to zero suddenly | |
Description
This function performs a count, either of…
1) The number of rows that match a condition,
2) The number of times a condition became true,
3) The number of times a value changes, or
3) The total amount that a value either increases or decreases
To count each individual row, use the where parameter. This will count each row individually - if we where each value is yes in the table below…
| Row # | Value |
|---|---|
| 1 | Yes |
| 2 | No |
| 3 | Yes |
| 4 | Yes |
| 5 | Yes |
| 6 | No |
…the answer will be 4, since there are four rows where the value is 'yes'.
Alternatively if we used when instead of where, the answer would be '2', because the value only changed to 'Yes' twice.
Example
If the frame contains the following attributes…
| Row # | Value |
|---|---|
| 1 | Yes |
| 2 | No |
| 3 | Yes |
| 4 | Yes |
| 5 | Yes |
| 6 | No |
{ "type": "count", "when": "{Value}='Yes'", "name": "Yesses" }
The final results will include a “Yesses” attribute with a value of 2.
ChangesIn
To count the number of changes, use changesin.
If certain values - such as '0' - should be ignored, add them in the ignores option, which is an array of values that should not be counted.
For example, if you had a 'Batch ID' number…
{ "type": "count", "changesin": "Schedule Job ID'", "ignored: [0], "name": "Batches" }
Counting Up/Down
You can also count based on an existing total - for example, a counter that records the number of items produced this batch/shift/order.
{ "type": "count", "up": "Conveyor 1.Total Items'", "name": "Total Produced" }
When counting up or down, drops back to zero will be ignored. If a value is expected to fall sharply, you can set the 'reset' parameter to 'hard'.
{ "type": "count", "up": "Conveyor 1.Total Items'", "reset": "hard", "name": "Total Produced" }
The difference is in how the system deals with when a value goes from high-to-low. In a 'hard' reset mode, the system expects that the counter will drop back to zero in all cases - it will not go backwards for any other reason.