Mondrian 1869 lag

[MONDRIAN-1869] - avg measures need to be aggregated in SQL similar to distinct-count. You cannot aggregate avg from separate queries because the count for the denominator is lost by then. cherry-pick from f1d5991