Volume Driven Allocations
Overview
One way to allocate costs is to measure some activity (here we generically refer to it as a volume) and then
assign a rate to the activity. The allocated cost is then the {% volume \times rate %}.
As an example, when allocating IT expense, a company could track where its IT staff spends its time (through a time
logging system). That is, the number of IT hours used by each business unit is logged, and then the IT expense
allocated to that unit is just the number of hours times the rate.
Sometimes the volumes are not as direct as the logging of hours. In such cases, it may be useful to find
something that can be measured and can stand as a proxy for the cost being allocated.
Data
The following script shows an example of a set of volumes and assigned rates.
var volumes = [
{ id: 1, accountid: 1, value: 10, type: 'account transaction' },
{ id: 2, accountid: 1, value: 10, type: 'account transaction' },
{ id: 3, customerid:1, value:1, type:'customer helpline' }
];
var rates = [
{ type: 'account transaction', rate: 2 },
{ type: 'customer helpline', rate: 20 },
]
Calculating Allocations
Once you have collected a set of volumes and rates, the calculation of rate times volume for each type
of volume is straightforward. The following code uses the
group module.
let groups = $group(volumes, p=>p.type)();
let rateAllocations = [];
for(let rate of rates){
let vols = groups[rate.type];
let allocation = {
type:rate.type,
charge: $list(vols).map(p=>p.value*rate.rate).sum()
};
rateAllocations.push(allocation);
}
Try it!