The XYTableGroupBy function aggregates data in a two-dimensional table that is stored as a delimited string.
When MyWraps2 is used to retrieve data from the ExcelWraps database, it returns the result either in a single column called an XTable, or in a two-dimensional format called an XYTable. An XYTable is a two-dimensional data structure represented as a text string, with the columns separated by semicolons and the rows separated by the pipe (vertical bar) character.
Example: the simple table below:
Fleet | Make | Depot |
800-01 | 2012 | Doncaster |
800-01 | 2015 | Doncaster |
800-02 | 2018 | Temple Mills |
800-03 | 2020 | East Ham Depot |
would be stored like this as an XYTable:
“Fleet;Make;Depot|800-01;2012;Doncaster|800-01;2015;Doncaster|800-02;2018;Temple Mills|800-03;2020;East Ham Depot”
Making database calls to aggregate data is convenient, but may consume unnecessary resources if the source data is already present in an XYTable. The XYTableGroupBy function makes it easy to count the number of cars per depot in the table. You can group the table on any relevant column and then make calculations on any column in the table, e.g. sum the values or determine the range of the values in the column.
=XYTableGroupBy("800-01;2012;Doncaster|800-01;2015;Doncaster|800-02;2018;Temple Mills|800-03;2020;East Ham Depot",1,"sum",2)
In the example table above, you could use XYTableGroupBy to sum the number in column 2 per fleet. The result of the operation is returned as an XYTable with the group identifier in column 1 and the result of the aggregation in column 2. For this sum operation, the function would return
800-01;4027|800-02;2018|800-03;2020
=XYTableGroupBy("800-01;2012;Doncaster|800-01;2015;Doncaster|800-02;2018;Temple Mills|800-03;2020;East Ham Depot",1,"count",2)
In the example table above, you could use XYTableGroupBy to count the number of rows per fleet. The result of the operation is returned as an XYTable with the group identifier in column 1 and the result of the aggregation in column 2. For this count operation, the function would return
800-01;2|800-02;1|800-03;1
=XYTableGroupBy("800-01;2012;Doncaster|800-01;2015;Doncaster|800-02;;Temple Mills|800-03;2020;East Ham Depot",1,"counta",2)
In the example table above, you could use XYTableGroupBy to count the number of rows per fleet that have any value. The result of the operation is returned as an XYTable with the group identifier in column 1 and the result of the aggregation in column 2. For this counta operation, the function would return
800-01;2|800-03;1
Note that the count functions do not return groups that have a count of 0.
=XYTableGroupBy(xyTable,groupColumn,aggregateFunction,aggregateColumn)
Points to the cell where the XYTable resides.
Enter the index of the column that will be used group the table when aggregating, e.g. 1 if you want a sum for each value in the first column. If you omit the group column, the entire values of the aggregateColumn will be aggregated and the function returns blank value for group column i.e. “;30”, therefore remove “;” to get the actual aggregate value.
Specify the function that you want to apply on the aggregateColumn, as a string value. The following aggregations are supported:
Enter the index of the column that will be used for the aggregation function, e.g. 2 if you want the sum for the second column.