Skip to main content

count

Counts how many times a given value appears in the input data. Returns a number.

The value to count can be a number or string. The function is case-sensitive.

The optional third parameter allows you to apply an amending function — also known as a helper function — to each data value prior to counting. You must write the helper function as a lambda expression.

Parameters

  • INPUT LIST OR TABLE (list or table region)

    The list or table region to search

  • TARGET (number or string)

    The value to count.

  • HELPER FUNCTION (function)

    Optional. The function to apply to each value prior to counting.

    You must write the helper function as a lambda expression — see the examples below.

Examples

The first parameter can take a list.

ATL in Script

Result

[[

myList = makeList(10, 30, 20, 10, 40, 30, 10)

count(myList, 10)

]]

3

[[

myList = makeList('Peter', 'PAUL', 'Mary', 'Paul')

count(myList, 'PAUL')

]]

1

To amend each input value prior to counting, use the optional third parameter.

ATL in Script

Result

[[

myList = makeList('Peter', 'PAUL', 'Mary', 'Paul')

count(myList, 'PAUL', name -> upper(name))

]]

2

The lambda expression name -> upper(name) converts each value to uppercase prior to the count.

Tip

See ATL Guide > Lambda expressions for further guidance.

Using count with table data

Assume a "Describe the Table" project with this data:

ID

Region

Branch

Sales

Row 1

1001

Southeast

Atlanta

357589.32

Row 2

1002

Northeast

Boston

294293.49

Row 3

1003

Midwest

Chicago

403603.17

Row 4

1004

South

Dallas

324722.58

Row 5

1005

South

Houston

306555.26

Row 6

1006

West

Los Angeles

457359.45

Row 7

1007

Midwest

Milwaukee

192238.52

Row 8

1008

Northeast

New York

468745.37

The first parameter can take a column variable.

ATL in Script

Result

[[count(Region, 'South')]]

2

[[count(Region, 'South', x -> x[0:5])]]

3

The lambda expression x -> x[0:5] reduces each Region value to its first five characters prior to the count.

Note

In a "Describe Row in Context" project, the column variable is RegionColumn.