I don't know if this solution could be right for your case.
I suggest you to give to the user the possibility to chose the 2 dimensions he want to use changing the value of 2 different variables.
Check out the attachment.
Nested_If_Performance.qvw 150.8 K
Have you read the blog by Rob Wunderlich called 'how not to choose an expression'?
He explains how QV calculates IF statements and that it will calculate both possible outcomes of the IF even we think it shouldn't. He also shows how to code around this and it might help the performance of your app!