Claasloader

My IT blog (and other stuff)

Dimensional (Volumetric) Weight Calculations in Ruby and Excel

| Comments

When you are writing software for logistics or trading companies, sooner or later you might have to deal with the concept of dimensional weight (sometimes called ‘volumetric weight’).

What Is Dimensional (Volumetric) Weight?

The first time I faced the term of dimensional weight, I was quite confused. So let me explain the background a little bit.

Simply spoken, dimensional weight is an additional number used when you ship a box via one of the big carriers like UPS, FedEx or DHL. The basic formula is

dimensional weight (kg) = box volume (cm³) / 5000

(There are variants of this formula, but that’s not important for the moment. The logic behind is always the same.)

Remembering your physics course back in high school, you see that units are not the same on the left and the right side of this equation. Weight is measured in kg, volume is measure in cm³, so isn’t this just a mistake? Well, what you have to accept is that ‘dimensional weight’ has no physical meaning. Rather it is a number used by logistics companies to simplify their cost calculations.

When - let’s say - UPS ship a box from A to B, they probably use a truck for transportation. The truck has a maximum loading weight, which is maybe 1000 kg. So the heavier your box is, the more capacity of the truck is used for your box. As a simplification, we might assume that cost is proportional to the weight. (For 1 kg you may pay 5$, for 2kg 10$.)

But there’s another limiting factor in the truck: the volume. You can only put up to maybe 10 m³ of stuff into the truck. So the second thing UPS needs to consider is how volumetric your box gets. If your box is very light but also very big, this somehow needs to go into the cost calculation. Dimensional weight is a concept to make this calculation easier. You can put it like this:

For a light and big box, dimensional weight is the weight of that tiny and heavy box which creates the same cost of transportation.

Implementation Details

At least UPS claims that dimensional weight is always rounded up to the next whole kilogram. So even for 1.01 kg, they may charge you 2 kg.

Sample Code

Note: You should check proper rounding method for your carrier and your country. The implementations below are for UPS.

Ruby

1
2
3
4
5
6
7
8
9
10
11
12
13
  def dimensional_weight(dims)
    # dims = [cm, cm, cm]
    return 0 if dims.size != 3
    round_ups(dims.inject(:*) / 5000.0)
  end

  # Round to the next 0.5 or 1 kg
  def round_ups(flt)
    x = flt - flt.floor
    return flt if x.zero?
    return flt.floor + 0.5 if x <= 0.5
    return flt.floor + 1.0
  end

Excel

1
2
3
4
5
6
|   | A      | B      | C      | D      | E      | F        | G                                 |
| 1 | Number | Weight | Size 1 | Size 2 | Size 3 | Subtotal | Dimensional                       |
|   | of     |        |        |        |        | Weight   | Weight                            |
|   | Boxes  | (kg)   | (cm)   | (cm)   | (cm)   | (kg)     | (kg)                              |
|---+--------+--------+--------+--------+--------+----------+-----------------------------------|
| 2 | 3      | 11.00  | 40     | 41     | 42     | 33.00    | = CEILING(C2*D2*E2/5000,0.5,1)*A2 |

Comments