DATA SECTION:So I have data in one sheet like this: TYPE    AMOUNT     YES/NOPig         20     YPig         30     NPig         10     YCow         20     YCow         30     NCow         50     NBat         10     NRESULT SECTIONI'm using Google Spreadsheets and have a table in another sheet. I would like to have a formula (placed in the cells like the one labeled [=?]) that gives me sums like thus: TYPE        YES      NOBat         [=?]    [=?]Cow         20      80Pig         30      30But I still need the formula. PROBLEM SECTIONI'm struggling. I want a formula in the results table that looks up in the data section for a match in type and SUMs the Ys for that type. I would like another formula that looks up in the data section for a match in type and SUMs the Ns for that type. I assume VLOOKUP or HLOOKUP, but I'm struggling getting the SUM in addition. I linked an example sheet here. ADDITIONAL EDITS AFTER THE POSTI don't need a query. I just need a formula that replaces the [=?] for each column in the result section. I just put a ton of info there as an example. 
How Do I Create a Google Spreadsheet Formula to SUM data based on two variables
google spreadsheets
If you add the following formula in the second sheet (A1).Formula=QUERY(Sheet1!A1:C9;SELECT A, SUM(B) WHERE B IS NOT NULL GROUP BY A PIVOT C)then the table will appear as you want.ExplainedHere an explanation of the formula, from the inside to the outside:the PIVOT C transposes the unique results from column C (turning rows into columns)the GROUP BY A only filters out unique values in column A. (the same as sheet TABLE!A2)the WHERE B IS NOT NULL ignores empty cellsthe SUM(B) adds the result of the querythe SELECT A simply displays column A, as unique values If you're only interested in individual results, then I suggest using the following formula: =IFERROR(SUM(FILTER(DATA!$B$2:B;DATA!$C$2:C=$B$1;DATA!$A$2:A=A2));)Here an explanation of the formula, from the inside to the outside:the FILTER function will retrieve the amounts for range B2:B, column B without the header, by filtering range B2:B for No and range C2:C for Yes.the SUM function will add them together.the IFERROR will leave a blank cell if an error occurred (not result).ScreenshotExampleSee example file I've prepared, where both samples are present: SUM data based on two variablesNoteThe formula in the example file is a bit different (the range is set to contain complete columns).