---
title: COUNTIF
url: https://www.tines.com/docs/formulas/functions/countif/
kind: formula-function
---

*[tines.com](https://www.tines.com/llms.txt) › [Docs](https://www.tines.com/docs/llms.txt) › [Formulas](https://www.tines.com/llm/docs/formulas.md) › [Functions](https://www.tines.com/llm/docs/formulas/functions.md)*

# COUNTIF

*[View on tines.com](https://www.tines.com/docs/formulas/functions/countif/)*

Returns the count of all elements in an array that are equal to the comparison argument.

**Categories:** Arrays, Lambdas

## Syntax

```
COUNTIF(array, comparison)
```

## Examples

### Example 1

Input:

```json
{
  "my_action": {
    "message": [
      "north",
      "south",
      "east",
      "west",
      "north"
    ]
  }
}
```

Formula:

```
COUNTIF(my_action.message, "north")
```

Output:

```json
2
```

### Example 2: Comparison can also be a lambda.

Input:

```json
{
  "my_action": {
    "message": [
      {
        "count": 6
      },
      {
        "count": 2
      },
      {
        "count": 1
      },
      {
        "count": 3
      }
    ]
  }
}
```

Formula:

```
COUNTIF(my_action.message, LAMBDA(item, item.count > 1))
```

Output:

```json
3
```

## Sample actions

```json
{
  "standardLibVersion": "13",
  "actionRuntimeVersion": "1",
  "agents": [
    {
      "disabled": false,
      "name": "COUNTIF",
      "description": "",
      "options": {
        "mode": "message_only",
        "loop": false,
        "payload": {
          "count_if": "=COUNTIF(my_action.arr1, 'llama')",
          "count_id_lambda": "=COUNTIF(my_action.arr2, LAMBDA(item, item > 3))\n",
          "counf_if_lambda_2_options": "=COUNTIF(my_action.arr1, LAMBDA(item, OR(item = \"dog\", item = \"cat\")))\n"
        }
      },
      "position": {
        "x": -45,
        "y": -6360
      },
      "type": "eventTransformation",
      "timeSavedUnit": "minutes",
      "timeSavedValue": 0,
      "monitorAllEvents": false,
      "monitorFailures": false,
      "monitorNoEventsEmitted": null,
      "form": null
    },
    {
      "disabled": false,
      "name": "My Action",
      "description": "",
      "options": {
        "mode": "message_only",
        "loop": false,
        "payload": {
          "arr1": [
            "dog",
            "cat",
            "llama",
            "dog",
            "tiger",
            "dog",
            "llama"
          ],
          "arr2": [
            "1",
            "2",
            "3",
            "4",
            "5",
            "6"
          ]
        }
      },
      "position": {
        "x": -45,
        "y": -6450
      },
      "type": "eventTransformation",
      "timeSavedUnit": "minutes",
      "timeSavedValue": 0,
      "monitorAllEvents": false,
      "monitorFailures": false,
      "monitorNoEventsEmitted": null,
      "form": null
    }
  ],
  "links": [
    {
      "sourceIdentifier": 1,
      "receiverIdentifier": 0
    }
  ],
  "diagramNotes": []
}
```
