Quite often worked this kind of aggregating the results of the inner calculation on their row-level because the set conditions couldn't be applied/fulfilled on the higher TOTAL levels respectively return there other results. But your expression looks a bit uncommon and therefore I suggest to review your object-calculation in regard with the datamodel.
Nevertheless it could be that you need different expressions on the different dimension-levels of your pivot. This could be reached with something like:
if(dimensionality() < 1, expr1, expr2)
To see which row has which level put dimensionality() directly as an expression in your object.