been trying to do this without asking here, but i couldn't

got 3 datasets (DS1, DS2, DS3). DS3 is bounded into DS2 and this one with DS1. all this DS has numeric fields (columns) wich i need to summarized at last of each DS with some basic mathematical stuff, like this:
DS1
____DS2, Num2
________DS3, Num3
________DS3, SUM(Num3)
____DS2, totalDS2 = (Num2 - SUM(Num3))
DS1, GrandTotal = SUM( totalDS2 )
i've been trying to do it with agregates but didn't get luck. also trying to do it with some JS, but also get stucked.
can anybody point me the right way to do it, please?

any help will be very much appretiated.