count

The count aggregate returns a count of non-empty cells, or attributes that are not null.

Synopsis

AFL% aggregate(array,count(attribute)[,dimension_1,dimension_2,...])

AFL% aggregate(array,count(*) [,dimension_1,dimension_2,...])

Summary

When using the count(attribute) syntax, the empty cells and NULLs are not counted.

When using the count(*) syntax, empty cells are not counted.  (NULLs are counted).

Examples

Find the Number of Non-Empty Cells or Non-Null values in an Array

  1. Create an array of 1's except for the element at (0,1) which is NULL:

    AFL% store(build(<v:int8>[row=0:1; col=0:1],iif(row=0 and col=1,null,1)), M);


    The output is:

    {row,col} v
    {0,0} 1
    {0,1} null
    {1,0} 1
    {1,1} 1
  2. Find the number of non-empty cells in the array:

    AFL% aggregate(M,count(*));


    The output is:

    {i} count
    {0} 4
  3. Find the number of non-null values of attribute v in the array:

    AFL% aggregate(M,count(v));


    The output is:

    {i} count
    {0} 3
  4. Find the number of nonempty and non-null cells for attribute v, per row:

    AFL% aggregate(M,count(v),row)


    The output is:

    {row} v_count
    {0} 1
    {1} 2
  5. Find the number of nonempty and non-null cells for attribute v, per column:

    AFL% aggregate(M,count(v),col)


    The output is:

    {row} v_count
    {0} 2
    {1} 1
  6. Remove the example array:

    AFL% remove(M)