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 | Searches a table column for increases in value | |
| down | Searches a table column for decreases in value | |
| origin | When the value reverses direction in up and down counting, this specifies the value to return to | |
| splitby | The column value to split the resulting data by | |
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" }
If you specify an origin value, the monitored value is expected to return sharply to this value as part of normal operation.
{ "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.
Splitting
Splitting effects up, down and changesin types of count.
You can split the results by a given value. For instance, if you wanted to find out what the most popular style of product was for a given day, you could split the production count by the product type.
{ "type": "count", "up": "Conveyor 1.Total Items'", "name": "Total Produced", "splitby": "Product.Type" }
This will output several different 'Total Produced' figures - one for each product type.
If Product Type is an discrete value in ARDI rather than text, the system will substitute the English name for the value. For example, rather than 'Product Type 4', it will be 'Product Type 1500CC Motor'.
This ensures that your analytics remain stable and don't require maintenance when new product lines are added in the future.