Sum of Margin

Similar to the Sum of Revenue calculation, except that this time, we are performing a different aggregation at the row level.

Sum of Margin = SUMX(
    transaction_lines,

    var _quantity = transaction_lines[quantity]
    var _price = transaction_lines[price]
    var _cost = transaction_lines[unit_cost]    

    return _quantity * (_price - _cost)
)