My colleague found a solution:
IF(HASONEVALUE([row_descriptor]), Expression_that_returns_binary_value, MAXX(values(Table_with_row_descriptors), Expression_that_returns_binary_value))
This checks if we are evaluating a normal row in the pivot table, or the "total" row, and uses MAXX only in the latter case.