Sorting by group aggregate

Sorting by group aggregate

DavidCarnleyDavidCarnley Posts: 1Questions: 1Answers: 0

In my data I have several columns, but let's talk about 2 of them: a DocumentID and a SentDate. A DocumentId can appear multiple times (many rows), each with a different SentDate.
I am grouping by DocumentID using rowGroup option/plugin.
I want to sort my groups such that the groups are ordered by the maximum SentDate within a group. That is, the raw data if sorted just by date might have documentIDs in this order 4,2,3,4,1,3,4,1,2,4,1,4 (most recent first). When grouped,
* document 4 group should be first (with all five of its rows) (becasue 4 has the most recent date of all docs),
* then document 2 group (two rows) (because the latest date in group 2 is less than the latest date in group 4 but later than the latest date in group 3),
* then document 3 group (two rows),
* then document 1 group (three rows).

So I need to sort (descending) by the latest date within each group (newest records first).

How can I do this? The grouping is fixed (always only be documentId), and the sort can be fixed (nice to have - allow user to swap sort order so oldest records are first)

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I don't believe that's possible - as you're grouping by the DocumentID for RowGroup, that needs to be primary sort, so the SentDate can be the secondary ordering with the grouping, but it wouldn't determine the ordering of the groups.

    Colin

Sign In or Register to comment.