Here's a different approach, not sure if it will work for your true setup.
I first converted all the quick table calculations into calculated fields
by dragging them (each separately) onto the Measure Pane.
This created a Calculation1 field which I renamed.
Then I made a [SortValue] field based off the parameter
- ( CASE [Rank by]
WHEN "Profit Diff" THEN [Profit Diff 1]
WHEN "Profit Diff %" THEN [Profit Diff 2]
WHEN "Quantity Diff" THEN [Quantity Diff 1]
WHEN "Quantity Diff %" THEN [Quantity Diff 2]
) // note the negative sign used to sort descending
This I placed on the Row Shelf as a discrete pill to the left of [Sub-Category]
so it forces the sort.
For the Top N part, I made a calculated field:
INDEX()<=[Choose Top N]
and placed that on the Filter Shelf and
set it's compute using to be [Sub-Category]
Please see workbook v18.1 attached in the Forum Thread:
286020sort.twbx 2.3 MB
Thanks you so much! Worked like a charm!