I recently post an article "Dynamically sort top N in a drill down hierarchy" on my blog at See It Your Way
the screen looks like this
there are 8 examples - 1 or 2 address your question - also the workbook containing the examples can be found at Tableau Public
If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution. Thank you.