Top n for metric grouped by dimension and across time dimension

I have a line chart that has a time dimension on the horizontal axis and the measure is grouped by another dimension. The group dimension has dozens of members. I would like to be able to change the visualization to only show the top n series groups based on the sum or average of the measure across the time dimension. I have not been able to figure out how to rank the measure by the groupings and maintain the series across the time dimension. I hope this makes sense, and does anyone have any ideas?

You can create a formula measure that calculates the sum or average for each series. For example, SUM($Measure$, $Series Dimension$) produces the sum of the measure for each series as alignment. This measure doesn’t have to be visible on the visualization.

With the formula measure in place, set the Top N using either the metric set's Top / Bottom Measure setting or a Formula Visualization with the TOP function.

Azar, thanks ! That worked perfectly for the top/bottom measure setting. I could not get it to work with the Formula visualization since I am actually displaying a different measure than the ranked one. I will use script to create a control for changing the top # value in the metric set. Thanks again.