Query that sum balance of different event

I have rephrased the query and I have posted till which point I got success and where it's breaking in below link