Use Generic GroupDescriptor
This help article will show you how to create generic expression GroupDescriptors
Generic GroupDescriptor
You can also group objects by the result of an equally complex operation:
Example 1: Create a generic GroupDescriptor
For more information you can check the Grouping section.