• I would be inclined to simply divide each alloc by SumOfAlloc and multiply by 100 to get a proper allocation which also adds up to the total (as long as you use a suitably precise datatype for the division).

    Much simpler and can be done in a single query if you want to.

    Also, dosn't allocate to zeros and spreads the unallocated amount in proportion to the existing allocations.