Margin Calculation

I am trying to calculate the average margin.


I have two columns: margin for the item and units sold.


For example:


If i sold 50 units at 30% margins and 2 units at 50% margin, my average margin would be roughly 31%

I need to do a summation of total units and total margin %


If I do not have the summation my average margins would be incorrect and show 40%.


How do I put that calculation in Beast Mode?