Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Seriously clever formula required...!

Dear all,


I have been trying to figure this out for so long I’ve actually lost the ability to even ask the question, but here goes...


I would like the information in the ‘Expenses input’ sheet (which is where I keep a running total of my business expenses) to be automatically summed (according to the category I assign the transaction) and displayed in the correct area of the ‘Profit & Loss’ sheet.


User uploaded file User uploaded file


If I had a working formula, the ‘Profit & Loss’ sheet in this example should look like this:


CELL D20 = £197.50 (which is the sum of all category 'T1' transactions in period 'April 6th - 30th')

CELL D22 = £149.19 (which is the sum of all category 'T3' transactions in period 'April 6th - 30th')

CELL E20 = £197.50 (which the sum of all category 'T1' transactions in period 'May')


It may be worth mentioning that when a paper receipt comes in to me, I assign it a category which is written on it in pen before being filed away, this system cannot change!


In the interest of avoiding confusion, us English folk use the date format DD/MM/YY!


Any help anyone could give would be enormously appreciated. Once I've figured this out I'll be able to add an income sheet as well as a VAT (value added tax) account which will improve my quality of life no end!


Thank you.

iMac, iOS 6.1.4, Numbers

Posted on Jul 26, 2013 11:21 AM

Reply
10 replies

Jul 26, 2013 12:13 PM in response to james.a.b

Hi James


Essentially, you need to collate across two categories - month, and expense type.


---


Create another column (which will be hidden) in the Expenses sheet. Call it 'collated' (for example).


Populate that column with this formula:


=MONTH($Date) & $Category


This will produce entries like 7T1 (expenses in July for category T1)


---


In the Profit and Loss sheet, create a header row called MonthID (hidden), which has the number for each month in corresponding columns.


In each Expenses cell, put this forumla:


=SUMIF(Expenses::$collated, "=" & $monthID & $Category, Expenses::$Nett)


This should put the total for that category for that month into each cell.


---


You can create extra header columns and rows, which are used for formulae, but hidden from view.


I might need to refine this, but that's a start 🙂

Jul 26, 2013 12:44 PM in response to james.a.b

Hi James


I was working off the visible headings in your sheets.


Numbers only references actual Numbers header rows and columns.


Create a header row at the top of your sheet, which will use the same headings you have in the visible section.


Hide the header row.


The MonthID is a header column, at the side, so the name will be in the leftmost column.

Jul 26, 2013 1:44 PM in response to james.a.b

Here's a screenshot with a simplified version of your spreadsheets.


The green parts are Numbers Headers. These can be hidden, and will still work.


I have highlighted the relevant columns and rows that are involved with the formulae.


Note that it is important to use the same upper and lower case when using header references that you have created.


Also, there is no need for a MonthID column in the Expenses sheet, as using MONTH($Date) will produce the required result.


User uploaded file

Jul 26, 2013 4:09 PM in response to james.a.b

Hi James,


You wrote:


"CELL D20 = £197.50 (which is the sum of all category 'T1' transactions in period 'April 6th - 30th')

CELL D22 = £149.19 (which is the sum of all category 'T3' transactions in period 'April 6th - 30th')

CELL E20 = £197.50 (which the sum of all category 'T1' transactions in period 'May')

"

Essentially, what you are looking for is a SUMIFS statement.


Here are two possibilities, both shown in the example:

User uploaded file


The small table on the left is a representation of part of your Expenses table, showing the expenses in your example.


The two tables on the right are representations of the active part of your P&L table, showing category totals for the sample expenses in the Expenses table. The error warning triangles in the lower table are expected, and are explained below. Several rows are hidden to reduce the size of the screen shot. The tables differ only in the formula used.



(Upper example):

D20: =SUMIFS(Expenses :: $E,Expenses :: $A,$A20,Expenses :: $D,">="&D$1,Expenses :: D,"<"&EOMONTH(D$1,0)+1)

(Lower example):

D20: =SUMIFS(Expenses :: $E,Expenses :: $A,$A20,Expenses :: $D,">="&D$1,Expenses :: D,"<"&E$1)


In each case, the fornula is filled down from D20 to the end of the categories, and filled right to the last column.


As the second formula references the header cell containing the full date at the top of its column AND the cell containing the date in the next column to the right, the lower version of the table will require one column beyond the last one for which sums are being reported


Both formulas reference the Date and Time value in the cell in row 1 of their own column. This MUST be a true Date and Time value, MUST be the first day of the period to be summed in its column, and MAY need to match the format of the Date and Time value used in column D of the Expenses table. (Note that I used April 1 for the first date. This can be changed to April 7 if you want to eliminate any entries prior to that date.)


The category codes in column A must match exactly those used in column A of the Expenses table.


You will need to change "Expenses" in the formula to the actual name of your Expenses table.


Row 1 is a 'working row', necessary to the formulas, but optional to the user's view. It may be hidden.


Row 2 of the P&L table uses a formula to extract the month from the date in row 1, and display the name of that month.


D2: =MONTHNAME(MONTH(D1))


Fill right a needed.


Details on the functions used may be found in the iWork Formulas and Functions User Guide. The guide may be downloaded via the Help menu in Numbers.


Regrds,

Barry

Jul 27, 2013 4:19 AM in response to Barry

Dear Barry, kharisma,


Thank you both for your help. I’m getting closer here but still not quite able to make this work. As I want to be able to understand the formula (rather than just having something that works and forgetting about it) it occurred to me that I could drastically shorten the length of the formula by omitting the date element and having a small separate table for each month like this:


User uploaded file


As well as making the formula far simpler, I think this is a nicer way for me and others to input data on a day to day basis.


So now, all the formula in D20 needs to do (see screenshot 2) is look at the Net values of categories equal to ‘T1’ (see screenshot 3) and sum them together.


User uploaded fileUser uploaded file


Thank you again so much for help so far, believe it or not this is the first time I’ve ever posted anything on a discussion board and I’m amazed on how helpful people are being!

Jul 27, 2013 9:40 AM in response to james.a.b

This does lead to a shorter formula.


If I'm reading your screen shots correctly, this should work. Two versions of the formula again, plus a variation that will be required if you have more than one table named (eg.) "May".


Data tables:

User uploaded file

P&L table (and Sheets list):

User uploaded file


D20: =SUMIF(April :: $A,$A20,April :: $E)


This is the 'simple, straightforward version. It can be filled down the column from D20, and will automatically adjust the $A20 reference to fit the new row. It will NOT adjust to the new tabe name as it is filled right.


E20: =SUMIF(INDIRECT(E$1&"::$A",),$A20,(INDIRECT(E$1&"::$E",))


This is the same formula, but uses INDIRECT to construct the first argument of SUMIF from the table name (eg. May) in row 1 of its column plus the text "::$A". This formula may be filled in both directions.


Variation:


The above formulas will work if each of the table names is unique within the document. If you have more than one table named with the month, the references to columns A and E must include the name of the sheet containing the target table.


D20: =SUMIF(Expense log::April :: $A,$A20,Expense log::April :: $E)


E20: =SUMIF(INDIRECT("Expense log::"&E$1&"::$A",),$A20,(INDIRECT(("Expense log::"E$1&"::$E",))


Regards,

Barry

Jul 27, 2013 10:45 AM in response to james.a.b

Hi James,


Further explanation 🙂


Collating requires adding just one extra column to the original Expenses table (and making sure the top row is a Header):


=MONTH($Date) & $Category

since you are collating for both month and category


---


The original Profit and Loss table required a single Row Header with the label Category in the appropriate column; also a single Column Header, with one extra row named MonthID.


There's no need for a formula for MonthID, as the values are stable - you will likely have the same layout year after year. Just enter the first couple of numbers, and drag to fill the series.


The formula for the totals is brief, and can be replicated to all cells, without any changes.


=SUMIF(Expenses::$Collated,"="& $MonthID & $Category, Expenses::$Nett)


=SUMIF(..., Expenses::$Nett)

Sum all Nett expenses, if ...


Expenses::$Collated,"=" & $MonthID & $Category

If the values in the Collated column equal the MonthID and the Category for this cell.


To me, this seems like the least work, for the required result.


Still, like you, I often explore several options before deciding on the solution that suits me best 🙂

Seriously clever formula required...!

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