CountDistinct

The CountDistinct function counts the number of values in a column.

CountDistinct (numbers, break_col, break_values)

where:

numbers references the column that contains the numbers on which the count of distinct (unique) values is calculated.

break_col is an optional parameter that references a break column.

break_value is an optional parameter that returns a distinct (unique) count of numbers column where value in break_col equals break_value.

Note:

The CountDistinct function differentiates actual values and not the rows. The Count function counts only the actual rows in a column. For example, if a column named “OS Operating Systems” has one hundred rows and shows data by Windows and UNIX systems, the CountDistinct function counts only the three operating systems and not the number of rows.

The following examples show the results of inserting the CountDistinct function in three separate tables.

Example 1

In this example, the CountDistinct function is used on the numeric column. The results are shown in the Computed column.

CountDistinct (Amount)

Table 152. CountDistinct Example 1

State

City

Amount

Computed

AZ

Tucson

112

8

CA

Burbank

240

8

CA

Glendale

240

8

FL

Palmetto

70

8

MD

Laurel

97

8

MI

Detroit

208

8

MN

Eagan

159

8

NY

New York

490

8

NY

Rochester

180

8

Example 2

In this example, the CountDistinct function is used on the numeric column and break_column. The results are shown in the Computed column.

CountDistinct (Amount, State)

Table 153. CountDistinct Example 2

State

City

Amount

Computed

AZ

Tucson

112

1

CA

Burbank

240

1

CA

Glendale

240

1

FL

Palmetto

70

1

MD

Laurel

97

1

MI

Detroit

208

1

MN

Eagan

159

1

NY

New York

490

1

NY

Rochester

180

1