---
title: Methods
slug: methods
docTags: 
createdAt: 2023-01-27T02:56:13.000Z
---

# Methods

Methods are special types of [Functions](docId\:IZsyKLqFBEtmslMltBMay) that apply to a [List](docId\:xWH_cUkHj9waqaEfb7H71) or Sequence of data. Usually, methods are used to aggregate data – such as counting or summing List values.

### Syntax

Methods are called like this, where `subject` is the subject of the method, such as the List or Sequence that is being aggregated:

`subject.methodName(parameter1, parameter2)`

If the method is passed an Expression as a parameter, you can use either of the following syntaxes -- they both mean the same thing:

`subject.methodName({expression})`
` subject.methodName{expression}`

The second is often preferred, for clarity and brevity.

Methods can be chained together to form a pipeline of evaluations -- for example:

` subject.methodName1{expression1}.methodName2{expression2}`

### Example Usages

Methods can be used anywhere in Carrot.

Most commonly, methods will operate on a List – for example, to calculate the total number of shares from the [Grants](docId\:Lpx5L8w1t54iPBqq8Eqjv) field, only counting grants that have a strike price of less than 10 cents, one could write:

`grants.filter{price < .1}.sum{shares}`

### Method List

| **Method**                                 | **Description**                                                                                                      |
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
| `.all()`                                   | Returns true if all of the items match an expression                                                                 |
| `.any()`                                   | Returns true if at least one of the items matches an expression                                                      |
| \`.count()                                 | Returns the number of items matching an expression                                                                   |
| \`.filter()                                | Returns a list of items that match an expression                                                                     |
| [.find()](docId:6Mwj2HJZ9ljkHmBfK0VVo)     | When called against a Table, queries for entities in that table matching the expression                              |
| \`.groupBy()                               | *Generally only used in Dashboards*. Groups the items by key, returning a SequenceGroupedBy, that can be aggregated. |
| \`.join()                                  | Returns a string that joins the items together.                                                                      |
| \`.limit()                                 | Returns a list of items, with the number of the items limited to a certain number.                                   |
| \`.map()                                   | Returns a list of items that have been transformed using the mapping expression passed in.                           |
| \`.max()                                   | Returns the maximum value of the items in the list, excluding nulls.                                                 |
| \`.mean()                                  | Returns the arithmetic mean (average) of the items in the list, excluding nulls.                                     |
| \`.min()                                   | Returns the minimum value of the items in the list, excluding null.                                                  |
| \`.none()                                  | Returns true if none of the items matches an expression.                                                             |
| \`.sort()                                  | Returns a list of items, sorted by an expression.                                                                    |
| \`.sortDesc()                              | Returns a list of items, sorted in descending order.                                                                 |
| `.sum()`                                   | Returns the sum of the items (optionally transformed with an expression).                                            |
| [.unique()](docId\:OYypYkrFY06bRSVJBFETI)  | Returns a list filtered down to its unique items                                                                     |

# Aggregators (deprecated)

Aggregators are special expressions used to aggregate values over time, only used in ChartHop Dashboards. However, **aggregators are now deprecated.**

We recommend that you replace their use with the corresponding ChartHop methods above. The Dashboards UI will be migrated to use Methods instead.

### Syntax

An aggregator in Carrot appears as a word followed by curly brackets, which contain an expression.&#x20;

`aggregator{expression}`

An aggregator performs a calculation on the parameter expression and returns a [Number](https://docs.charthop.com/ucI5-number) value based on the aggregator's logic.

All aggregators are case-insensitive.

### Usage

Aggregators are only available in Dashboards.

### Migration

To replace the use of an Aggregator currently used in a Dashboard with a Method call instead, use the following syntax:

`db.job.find(jobFilter).aggregator{expression}`&#x20;

For example, this aggregator call:

`count{headcount if department:engineering}`&#x20;

Becomes:

`db.job.find{department:engineering}.count{headcount}`

### Aggregator List

| **Aggregator**                                 | **Description**                                                                                                                                                   |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [count\{}](https://docs.charthop.com/count)    | Counts the number of times a given expression evaluates to a truthy value. All non-truthy values, such as `null`, an empty string, `0`, or `false` are discarded. |
| [max\{}](https://docs.charthop.com/max)        | Returns the largest value of a given expression. All non-numeric values are discarded.                                                                            |
| [mean\{}](https://docs.charthop.com/yOFs-mean) | Returns the average of all values of a given expression. All non-numeric values are discarded.                                                                    |
| [min\{}](https://docs.charthop.com/exqD-min)   | Returns the smallest value of a given expression. All non-numeric values are discarded.                                                                           |
| [sum\{}](https://docs.charthop.com/sum)        | Returns the sum of all values of a given expression. All non-numeric values are discarded.                                                                        |

