Q:

Sum particular cells only if matched a particular string from a dropbox

I have this Project Costing spreadsheet, where I track all my project profit, expense etc.
The number of items in every project is always different. Then I have a few states of the projects such as: in progress, invoiced, paid, closed etc. 

What I need is to get a sum of all my sales, cost and profit ONLY of the projects that are Closed. You can see in the top line of each project I have a data validation cell where I select the state of the project. Once it's closed I need to add its sales, cost and profit into the top cells (orange, blue & green).
I can't for the life of me, figure out how to do that. Tried sumif plus queries no luck. Any ideas?
Here is a sample of the spreadsheet https://docs.google.com/spreadsheets/d/18Y-2jeKue9aH4gGdKHZjECygo47JFOp2W11C2sy7fJk/edit?usp=sharing
EDIT:
I found a workaround. by repeating the status of the project in the cell next to Total: cell. and then just simply using =SUM(QUERY($B$26:$M$46,"select M WHERE B = 'Closed'")). But I am sure there are more elegant and robust ways of solving my problem.
Cause sometimes I have cases when only 50% of the whole sale price was paid(upfront payments), so I'd like to reflect that as well.

A:

if you are not happy with your workaround you can do:
=ARRAYFORMULA(SUM(QUERY({VLOOKUP(ROW(A12:A), IF(IFERROR(REGEXEXTRACT(K12:K, 
 "Undefined|Quote|Accepted|In-progress|Cancelled|On-hold|Not Paid|Paid 50%|Closed"))<>"", 
 {ROW(A12:A), K12:K}), 2, 1), C12:C, M12:N}, 
 "select Col3 where lower(Col1) = 'closed' and lower(Col2) = 'total:'", 0)))

and for Profit:
=ARRAYFORMULA(SUM(QUERY({VLOOKUP(ROW(A12:A), IF(IFERROR(REGEXEXTRACT(K12:K, 
 "Undefined|Quote|Accepted|In-progress|Cancelled|On-hold|Not Paid|Paid 50%|Closed"))<>"", 
 {ROW(A12:A), K12:K}), 2, 1), C12:C, M12:N}, 
 "select Col4 where lower(Col1) = 'closed' and lower(Col2) = 'total:'", 0)))

