scaling and groyp by in weighted average