Tech Tip: Counting the amount of Distinct Values of a Field
PRODUCT: 4D | VERSION: 15 R4 | PLATFORM: Mac & Win
Published On: July 19, 2016
As of v15 R4 a new parameter has been added to the DISTINCT VALUES command. This new third and optional parameter uses a Numeric type array and returns the number of times a distinct value is found corresponding to the results returned in the array of the second parameter.
For example:

The following:
will return:

This is useful for statisical analysis of data and it is also posible to reorder the results in order of most frequent to least using the SORT ARRAY command.
For example:

The following:
ALL RECORDS([Table]) ARRAY TEXT($arrText;0) ARRAY LONGINT($arrLong;0) DISTINCT VALUES([Table]Field;$arrText;$arrLong) TRACE |
will return:

This is useful for statisical analysis of data and it is also posible to reorder the results in order of most frequent to least using the SORT ARRAY command.