Select sum(qtyOrdered) from SalesLine order by SalesLine.LineNum Desc group by salesLine.LineNum, salesLine.CustAccount
Note: the order of columns in "Order By" should be same as in "Group By" else it will not work.
In case of query, the addsortfield should be done before adding the addGroupByField fields
ds.ordermode(OrderMode:GroupBy) should not be used (using this will prevent the OrderBy from working but there is a draw back. The grid sorting will not work)
Datasource-> init() method
QueryBuildDataSource OperationsDs;
;
OperationsDs = this.query().dataSourceTable(tablenum(CAP_OperationsList));
OperationsDs.addSortField(fieldNum(CAP_OperationsList, CAP_ProfileReferenceGroupId),sortOrder::Ascending);
OperationsDs.addSortField(fieldNum(CAP_OperationsList, CAP_CutLength),sortOrder::Descending);
OperationsDs.addGroupByField(fieldnum(CAP_OperationsList, CAP_ProfileReferenceGroupId));
OperationsDs.addGroupByField(fieldnum(CAP_OperationsList, CutGroupId));
//OperationsDs.orderMode(OrderMode::GroupBy);