DISTRIBUTION(recordset [, fields ] [, NAMED( name ) ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

recordsetThe set of records on which to run statistics.
fieldsOptional. A comma-delimited list of fields in the recordset to which to limit the action. If omitted, all fields are included.
NAMEDOptional. Specifies the result name that appears in the workunit.
nameA string constant containing the result label. This must be a valid label (See Definition Name Rules)
UNORDEREDOptional. Specifies the output record order is not significant.
ORDEREDSpecifies the significance of the output record order.
boolWhen False, specifies the output record order is not significant. When True, specifies the default output record order.
STABLEOptional. Specifies the input record order is significant.
UNSTABLEOptional. Specifies the input record order is not significant.
PARALLELOptional. Try to evaluate this activity in parallel.
numthreadsOptional. Try to evaluate this activity using numthreads threads.
ALGORITHMOptional. Override the algorithm used for this activity.
nameThe algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options.

The DISTRIBUTION action produces a crosstab report in XML format indicating how many unique records there are in the recordset for each value in each field in the recordset.

When there is an excessively large number of distinct values, it returns an estimate in this form:

  <Field name="seqnum" estimate="4000000"/>

The DECIMAL data type is not supported by this action. You can use a REAL data type instead.


SomeFile := DATASET([{'C','G'},{'C','C'},{'A','X'},{'B','G'}],
     {STRING1 Value1,STRING1 Value2});
/* The result comes back looking like this:
<Field name="Value1" distinct="3">
 <Value count="1">A</Value>
 <Value count="1">B</Value>
 <Value count="2">C</Value>
<Field name="Value2" distinct="3">
 <Value count="1">C</Value>
 <Value count="2">G</Value>
 <Value count="1">X</Value>

namesRecord := RECORD
  STRING20 surname;
  STRING10 forename;
  INTEGER2 age;

namesTable := DATASET([
  {'X','Z',5}], namesRecord);

doFirst := DISTRIBUTION(namesTable, surname, forename, NAMED('Stats'));
/* The result comes back looking like this:
<Field name="surname" distinct="3">
 <Value count="2">Halligan</Value>
 <Value count="1">X</Value>
 <Value count="1">Salter</Value>
<Field name="forename" distinct="4">
 <Value count="1">Abi</Value>
 <Value count="1">Kevin</Value>
 <Value count="1">Liz</Value>
 <Value count="1">Z</Value>

//Post-processing the result with PARSE:
       SELF.line := WORKUNIT('Stats', STRING))));
res := RECORD
  STRING Fieldname := XMLTEXT('@name');
  STRING Cnt := XMLTEXT('@distinct');

DoNext := PARSE(x, line, res, XML('XML/Field'));