You can use Dimensionality() to identify the total rows and create an expression that use Dimensionality like this:
If(Dimensionality() = 0, <total row expression here>, <detail row expression here>)
If you have more than one dimension, then the value of Dimensionality will equal the number of dimensions for the detail rows. The partial sums will have Dimensionality values between one less than the number of dimensions to 0, according to the partial sum level. The total row, or partial total row expression will often be a Sum(Aggr()) type of expression.
If you provide more information on your requirements, then we can help you with the expression.
Hope that helps