04 Group - AndrewMB2/Logic-Architect-for-Excel-VBA GitHub Wiki
Group method
Groups data. Returns True if successful, otherwise False.
Applies to
| TableData | ArrData | RsetData | Xdata | XShared |
|---|---|---|---|---|
| ✓ |
Parameters
| Name | Type | Description |
|---|---|---|
| GroupFields | Value or array | The fields to be summarised. |
| GroupFunctions | Value or array | The summarisation functions to be used. |
The user specifies which fields are to be grouped (in the GroupFields parameter) and what function is to be applied to each when grouping the data (in the GroupFunctions parameter). Where there are multiple fields, the group function will be in the position in GroupFunctions corresponding to the field it applies to in GroupFields.
All the fields not specified are treated as key fields, i.e. all records for which all these fields are equal are grouped together. If there are no such fields, the result of the group (on a non-empty object) is a single record.
Group functions are:
- Sum totals the values
- Count counts the values
- Average calculates the arithmetic mean
- Max returns the maximum value
- Min returns the minimum value
- First returns the first value
- Last returns the last value
- UniqueList returns a comma-separated list of unique values, with a space after the comma
- NumArray creates an array normally of numeric or date data (values as text separated by commas enclosed in {} brackets)
- TextArray creates a text array (values as text delimited by double quote characters separated by commas enclosed in {} brackets)
- ArrArray creates a 2-dimensional array from 1-dimensional arrays (each set of values separated by semicolons enclosed in {} brackets)
Where the group function is any type of array, the field is first converted to a text field if necessary. This can be reversed using RestoreTypes after an ungroup operation.
In the case of text arrays, certain characters are replaced by escape sequences
| Character | Escape sequence |
|---|---|
| \ | \1 |
| , | \2 |
| ; | \3 |
| " | \4 |
These are restored back to the original characters when the data is ungrouped.
More information on arrays can be found in Transforming Data.
The user can write their own group function if required. More information on user defined functions can be found in Transforming Data.