The best way to do this is to split it up in two parts. First part is to build the table without the total, and second part is to use that query within a dataviewjs query to build the total and add that to the result of the previous result.
A similar approach has been used here: