The distinction between an exploratory calculation and a shared metric is useful. I’d also make the aggregation rule explicit in tests: a weighted margin should be computed from summed profit and summed revenue, while zero or missing denominators need a deliberate policy. That catches cases where each row looks right but the grouped result answers a different question.