Using SUMIF with values from another sheet

I've created the sheet Expense Report, which includes tables Expense Information, Expense Details and Signatures (from a template).

In the table Expense Details I have these data:

User uploaded file

Where Date is column A, # is column B and so on.

Then I have a sheet Expense Table with only a table Table 1. Which is:

User uploaded file

Where 2015 is column A, water is column B and so on.

I would like for Table 1 to represent the summary of the costs for every Expense Type by month. For example: I want F2 to have the sum of the expenses called common costs in august (so in this case common costs with no note, with note overdue and with note emergency fund).

I tried the formula: =SUMIF(Expense Details :: B2:B8, "=c", Expense Details :: D2:D8), but "The formula contains a syntax error". I tried with ' instead of ", tried putting $, like =SUMIF(Expense Details :: B2:B8, '=c', Expense Details :: D2:D8) or =SUMIF(Expense Details :: B$2:B$8, "=c", Expense Details :: D$2:D$8), but they didn't work.

I'm out of ideas. Could someone please help me out?

MacBook Pro, OS X Yosemite (10.10.5), Numbers '08

Posted on Feb 15, 2016 11:44 AM

Reply
9 replies

Feb 16, 2016 6:43 AM in response to Umetnica

Hello


If you're using Numbers v1 ('08) as indicated in your profile, you'd need to introduce index column to consolidate filtering attributes and use SUMIF() with the condition on it because Numbers v1 does not have SUMIFS() function.


E.g.,



User uploaded file



DATA (excerpt) A1 date A2 2015-08-14 A3 2015-08-20 B1 class B2 ="c"&RANDBETWEEN(1,5) B3 ="c"&RANDBETWEEN(1,5) C1 cost C2 =RANDBETWEEN(1,20)*10 C3 =RANDBETWEEN(1,20)*10 D1 y|m|c index D2 =YEAR(A2)&"|"&MONTH(A2)&"|"&B2 D3 =YEAR(A3)&"|"&MONTH(A3)&"|"&B3



REPORT (excerpt) A1 2015 A2 =LOWER(MONTHNAME(MOD(H2-1,12)+1)) A3 =LOWER(MONTHNAME(MOD(H3-1,12)+1)) B1 c1 B2 =SUMIF(DATA::$D,$I2&"|"&B$1,DATA::$C) B3 =SUMIF(DATA::$D,$I3&"|"&B$1,DATA::$C) C1 c2 C2 =SUMIF(DATA::$D,$I2&"|"&C$1,DATA::$C) C3 =SUMIF(DATA::$D,$I3&"|"&C$1,DATA::$C) D1 c3 D2 =SUMIF(DATA::$D,$I2&"|"&D$1,DATA::$C) D3 =SUMIF(DATA::$D,$I3&"|"&D$1,DATA::$C) E1 c4 E2 =SUMIF(DATA::$D,$I2&"|"&E$1,DATA::$C) E3 =SUMIF(DATA::$D,$I3&"|"&E$1,DATA::$C) F1 c5 F2 =SUMIF(DATA::$D,$I2&"|"&F$1,DATA::$C) F3 =SUMIF(DATA::$D,$I3&"|"&F$1,DATA::$C) G1 total G2 =SUM(B2:F2) G3 =SUM(B3:F3) H1 m H2 8 H3 9 I1 y|m index I2 =A$1+QUOTIENT(H2-1,12)&"|"&MOD(H2-1,12)+1 I3 =A$1+QUOTIENT(H3-1,12)&"|"&MOD(H3-1,12)+1




Notes.


Formula in DATA::D2 can be filled down.


Formulae in REPORT::A2, REPORT::G2 and REPORT::I2 can be filled down.


Formula in REPORT::B2 can be filled down and right across B2:F9.


DATA::D and REPORT::I are index columns.


REPORT:H holds month numbers in year specified in REPORT::A1. Month number > 12 indicates month in following year.


The first and the last rows in both tables are header and footer rows.


Tables are built with Numbers v2.



Good luck,

H

Feb 22, 2016 3:19 PM in response to Umetnica

HI Umetica,


Here's an expansion/explanation of Hiroto's formulas.


DATA table

This is a table of sample data. Columns A, B and C are functionally equivalent to columns A, B and E (or A, C and E) of your Expense Detail table

Column A:

Contains date for each entry. The dates are entered directly.


Column B:

The entries here are equivalent to the information in columns B (or C) of your Expense Detail table. Each identifies one of the expense types listed in row 1 of the REPORT table, or in your example, Table 1 on the Expense Table sheet.

For the example, the class names are assigned randomly among the five class names, c1 through c5, using the formula shown.


Column C:

The entries here are equivalent to the information in column D (Cost) of your Expense Detail table.

For the example, each expense is a random multiple of 10 generated by the formula shown.


The three columns above are used to create a filled table of data. You already have the data in your Expense Detail table, so you may safely ignore the formulas above. The one in column D, though, is required in a column added to your Expense Detail table.


Column D: Index y|m|c

This column contains an index of the data entries in columns A, B and C, labelling each entry with a string containing the year, month number, and expense category, separated by the pipe character ( | ). The result is read by SUMIF to determine if the cost on this row is to be included in the sum for the cell containing (this copy of) SUMIF.


DATA::D2: =YEAR(A2)&"|"&MONTH(A2)&"|"&B2

YEAR(A2) reads the date and time value in cell A2, and returns the four digit date : 2015

& is the concatenation operator. It means 'append what follows to the existing text string.'

"" are text markers. Together they mean 'everything between us is text'

&"|" appends a pipe character to the year: 2015|

&MONTH(A2) MONTH(A2) reads the date in A2 and returns the (number of the) month ( 8 ); & appends the result to the string: 2015|8

&"|"&B2 appends a second pipe character after the month number; B2 reads and returns the contents of cell B2; the second & appends this to complete the string: 2015|8|c4


The formula in D2 is filled down to the rest of column D, and creates an index value for each line.


REPORT table:


Entered values:

A1: The year for which the data is being summarized. The entry is a four digit number.

B1 to F1: class/category names for expenses. These must be exact matches with the class names used in column C of the DATA table.

H2 to H9: number of the first month to be summarized, then incremented by 1 for each row. Note that the series of numbers continues beyond 12.


All other values on this table are created by the five formulas below:


A2: =LOWER(MONTHNAME(MOD(H2-1,12)+1))

Converts the number on this row of column H to the equivalent month name.

MOD(n,d) returns the remainder when a number (n) is divided by and other number (d). The -1 and +1 adjust the number and the remainder to make the end result range from 1 to 12 instead of 1 to 11, then 0.

MONTHNAME() converts that number to the name of that month.

LOWER() converts all letters in the name to lower case. If you want the name to begin with a capital, replace LOWER() with PROPER()

Fill this formula down column A to get the names of the other months.


I2: =A$1+QUOTIENT(H2-1,12)&"|"&MOD(H2-1,12)+1

This constructs the y|m part of the y|m|c index string needed by SUMIF. For a summary running from January to December in a single calendar year, the formula could be very much simplified. In that case, the year part would always by the number in A1, the month part would be the value in H2, and the values in column H would never be greater than 12. Formula: =A$1&"|"&H2 The rest is needed to handle dates beyond the end of the calendar year shown in A1.


A$1 returns the number in A1. The $ here is a fixed reference operator that keeps the row 1 reference constant as the formula is filled down column I.

+QUOTIENT(H2-1,12) returns the whole number answer when the number one is subtracted from the number in H2 and the result is divided by 12. The result is added to the year number returned above.

&"|"& appends a pipe character, as described above. The second & appends the result below.

MOD(H2-1,12)+1 returns a month number in the range 1 to 12. See previous section (cell A2 formula) for details.


The end result in I2 is 2015|8


B2: =SUMIF(DATA::$D,$I2&"|"&B$1,DATA::$C)

This constructs a y|m|c index specific to cell B2, using the y|m part in this row of column I, another pipe character, and the class/category part in row 2 of this column, then uses that y|m|c index value to select the items in DATA:: column D to be added.

SUMIF(test-values, condition, sum-values)

test-values: the y|m|c index values in column D of DATA

condition: matches the y|m|c index value for this cell ($I2&"|"&B$1 — this row of column I (2015|8) &"|" ( | ) & row 1 of this column ( c1 ) — 2015|8|c1

sum-values: the values in DATA::$C, summed if they are on a row with a test value matching the condition.


This formula is filled right to F2, then the row of formulas B2 to F2 is filled down. The $ operators keep the references to columns D, C and I fixed to those columns, and the references to row 1 fixed to that row. The references to column B and to row 2 are relative references and keep the same position relative to 'this cell' as the formula is filled into other cells. 'This cell' means "the cell containing 'this copy' of the formula.


G2: =SUM(B2:F2)

Calculates total expenses for the month recorded in this row. Fill down column G


B10: =SUM(B)

Calculates the total expenses for this column (category). Fill right to F10.

Row 10 must be a Footer row.


Row 1 is a Header row.

Column 1 is a Header column.


Regards,

Barry

Feb 22, 2016 3:39 PM in response to Umetnica

I am sorry, but I can't seem to find where SUMIF is used in the template you indicated.


SGIII is referring to a template included with Numbers 3, the current version. Personal Budget in Numbers '09 (and, if included, in Numbers '08) was a different document.


Try Checking Register, if this or a similar chequebook template was included with Numbers '08. The '09 version included a table that summarized expenditures by category using SUMIF.


Regards,

Barry

Feb 22, 2016 11:30 PM in response to Umetnica

Hello Umetnica,


As for the working of formulae, please read the detailed explanations written by Barry.


One thing I noticed in your screenshots is that you're using comma for decimal separator in which case the argument separator in formula is to be semicolon and not comma.


Such as



=SUMIF(DATA::$D;$I2&"|"&B$1;DATA::$C)




in lieu of



=SUMIF(DATA::$D,$I2&"|"&B$1,DATA::$C)




Regards,

H

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using SUMIF with values from another sheet

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.