There is no way for the model to tell if the dimensions are expanded or collapsed. It may be possible to check via deep dive into javsacript, or check if somebody has done something like this in an extension on Qlik Branch:(https://developer.qlik.com/
Dimensionality() will not help here as it is not dependent on the dimensions being expanded or collapsed.
Logic will get you from a to b. Imagination will take you everywhere. - A Einstein