I think your expression should be: sum(A) * only(B). Your second expression aggregated B and led therefore to the wrong results. The third expression had a incorrect syntax and should be rather like: sum(aggr(sum(A)*only(B),siteid)).
But why will you use them? Also why didn't you hide NULL in field A?
To aggeregations and especially with the aggr-function see here: