When you want to make complex queries over Excel sheet that is almost impossible. Yet by Google Docs Spreadsheet Query() function you can write SQL and retrieve whatever you want.
=query(A2:I1000;“select sum(H) WHERE D=‘mrkt’”)
Gets only expenditures which about ‘mrkt’ (market) from A2:ı10000 TABLE then gets sum.
When you write function by this way, the function returns extra header. You can remove it:
=query(A2:I1000;“select sum(H) WHERE D=’mrkt’ label sum(H) ”“)