It would be much easier if you format your code in a way that the structure can be understand.
But the error message should give you an hint - you can not build a sum on a sum within one statement.
so check if you find something like sum( ...sum(...))
funny reply - you need to avoid them as otherwise you will not get a result as the syntax is not supported.
But to help you much more details would be required. Are you group this? What should the different summs express?
And as stated above I have very limited passion to reformat this for you to get a clue what you want to achive.