A formula for the electrical conductivity in lattice systems