Can this Xpath work
sum(xdXDocument:GetDOM("TOSSReceive")/dfs:myFields/dfs:dataFields/d:TOSS[xdXDocument:GetDOM("TOSSReceive")/dfs:myFields/dfs:dataFields/d:TOSS/@employeeDepartment = ../../dfs:dataFields/d:TOSS/@employeeDepartment]/@monthlyExpenses)
or is it best to edit the SQl connection to do this