Thermal and other transport coefficients were recently shown to be largely independent of the microscopic representation of the energy (current) densities or, more generally, of the relevant conserved densities/currents. In this Article, we show how this gauge invariance, which is intimately related to the intrinsic indeterminacy of the energy of individual atoms in interacting systems, can be exploited to optimize the statistical properties of the current time series from which the transport coefficients are evaluated. To this end, we introduce and exploit a variational principle that relies on the metric properties of the conserved currents, treated as elements of an abstract linear space. Different metrics would result in different variational principles. In particular, we show that a recently proposed data-analysis technique based on the theory of transport in multicomponent systems can be recovered by a suitable choice of this metric.