I am having a report that designed to display the net sales and purchases amount of a given item within a given store. The report having 2 groups the first one is on the store and the second one is on the item and it looks like the example below:
Store: store_name [Group Header]
Item : item_name [Group Header]
[Qty] [DocNum] [DocType] [Detail]
[500] [ 8 ] [ S ]
[200] [ 3 ] [ P ]
Total Sales 500 [Group Footer]
Total Purchases 200
[Group Footer]
The totals fields are a running total fields not a summary field. All what I need is to sort the items within the store group according to either the higher sales or purchases amount and such sorting will be done through a sorting option represented by a boolean parameter value. If the parameter value is false the item with the higher sales amount will be first in order then the next item in amount etc. If the parameter value is true then the item with the higher purchases amount will be first in order then the next item in amount etc. Unfortunately, I cannot use the Group Sort option under Report menu as I do not have summary based on the group and therefore the Group Sort option is disabled and even if it is not it will sort according to a summary fields not on the running total fields. Does anyone has an idea about how to achieve such sort?!!!
What I have tried:
I tried to achieve the result through the database using the order by clause however that won't work correctly as I expected