How to add cell values for previous 8 months data only

I have an line item 'Amount' with data values. second line item(months applicable) which is boolean checked for only 8 previous month of current month. I want to add the values of these Boolean checked months only to be summed.


Can I please get some guidance here please?