Never include cell value in excel calculation - excel

tl;dr Is it possible to label cells as 'ignore' (or equivalent) so that if they are included in the range of a SUM function, they are not included in the calculation and therefore outputted value?
I have created a complex table that depicts revenue over the next few years. The table rows run continuously through the months with no break between December of one year and January of the next. I have realised I need to put in a Total column at the end of each year. If I select each Jan column and click insert, I get a vacant column at the end of each year that can be used for my total column (to the left of each Jan). However, I use SUM extensively in each row and I do not want any of the cells in the Total columns to be included in any of the calculations of the cells for the months. Is it possible for me to write my formulae in each Total column cell and then somehow specify that I do not want this value to be included in any calculations at all i.e. is there some sort of 'ignore' label i can apply to these cells? I know the alternative is to manually change each formula, but I have 5 years worth of predictions each with 50 rows and each cell has multiple SUM functions in it...

Say we have values in column A from A1 through A400, but some of the items are intermediate subtotals, etc. We want to sum column A, but omit the subtotals.
In column B place a 1 in rows that you want to process and a 0 in rows you want to skip
Then use:
=SUMPRODUCT((A1:A400)*(B1:B400))

Two options:
Use the SUBTOTAL function to calculate those subtotals, and the AGGREGATE function to do the sum at the end, as it has an option that lets you ignore SUBTOTAL results.
Use a PivotTable. You can then easily subtotal by year or whatever else you want.
I would personally go for option 2

Related

advanced filter w/ 1 row above

UPDATE - this was resolved with:
=OR(ISNUMBER(SEARCH("225522",A2)),ISNUMBER(SEARCH("225522",A‌​3)))
As an advanced filter criteria.
The goal was to find 225522 on the second row, and pull the row above it which was accomplished with the above along with the row containing 225522.
Original question
I have several thousand lines on an excel sheet and each second line has a header line labelled USD. I need to filter to find all of the 225522 rows but I need to include the row above it with the USD.
Example:
USD
11111.222222.333
USD
11111.225522.333
USD
11111.222222.333
USD
11111.222222.333
USD
11111.225522.333
I can filter 225522 and usd, but that would just unfilter all of the rows with 222222 leaving me to manually delete thousands of USD rows. It looks like the below...
USD
USD
11111.225522.333
USD
USD
USD
11111.225522.333
But I need it to look like
USD
11111.225522.333
USD
11111.225522.333
Is there a way to filter 225522 and keep the row above it to achieve my example above?
Use an advanced filter with formula criteria like:
=OR(ISNUMBER(SEARCH("225522",A2)),ISNUMBER(SEARCH("225522",A‌​3)))
where A2 is the first row of data in the relevant column and A3 is the second row.
This is may or may not fit your definition of filter.
In an unused portion of your sheet or in a new sheet use the forllowing formula assuming that your data is in the range A3:A2003
=AGGREGATE(15,6,ROW($A$3:$A$2003)/ISNUMBER(SEARCH("22522",$A$3:$A$2003)),ROW(A1))
That will generate a list of row numbers that match your criteria. What you want to do now is have ROW(A1), increase by 1 every two rows it gets copied down. Then you will want to put an if statement in that so that if ROW(A1) is odd, your use the row number -1 to get your USD. and if even that you leave the row number alone. Now tie that in with INDEX and you will generate the list you are looking for.
so to get it to count every second row increasing by 1 we could use something like:
=INT((ROW(A1)+1)/2)
This would turn our formula into:
=AGGREGATE(15,6,ROW($A$3:$A$2003)/ISNUMBER(SEARCH("22522",$A$3:$A$2003)),INT((ROW(A1)+1)/2))
in order to get our -1 to the row number we could incorporate something like:
=-ISODD(ROW(A1))
incorporating that into the previous formula would result in:
=AGGREGATE(15,6,ROW($A$3:$A$2003)/ISNUMBER(SEARCH("22522",$A$3:$A$2003)),INT((ROW(A1)+1)/2))-ISODD(ROW(A1))
The above could also have been achieved with an if statement but I decided to take a short cut.
The last step will be to incorporate it into an INDEX formula. which will wind up looking like:
=INDEX($A:$A,AGGREGATE(15,6,ROW($A$3:$A$2003)/ISNUMBER(SEARCH("22522",$A$3:$A$2003)),INT((ROW(A1)+1)/2))-ISODD(ROW(A1)))
Now you have the formula, you just need to copy it down as far as you need to go. It will start spewing errors when you run out of acceptable rows.
Alternatively you can set it up to display "" when there is an error/it runs out of rows by using the following:
=IFERROR(INDEX($A:$A,AGGREGATE(15,6,ROW($A$3:$A$2003)/ISNUMBER(SEARCH("22522",$A$3:$A$2003)),INT((ROW(A1)+1)/2))-ISODD(ROW(A1))),"")
The draw back to this method is that it performs array like calculations. As such you should limit its use to a defined range and not full column references within the AGGREGATE function. Having said that the Advanced filter option listed in your comments seems much simpler and probably a hell of a lot faster.
UPDATE
Since you need to pull multiple columns, I would adjust your INDEX portion of the formula. Now assuming your criteria column (column where the 225522 is located) is column F I would modify your formula as follows:
=IFERROR(INDEX($F:$F,AGGREGATE(15,6,ROW($F$2:$F$4401)/ISNUMB‌​ER(SEARCH("225222",$‌​F$2:$F$4401)),INT((R‌​OW(A1)+1)/2))-ISODD(‌​ROW(A1))),"")
Now in order to return the same row but different columns there are two ways to approach this. Either change the $F:$F to the appropriate column for each column you want to return or change the range from F:F to F:P and add a column reference to the index. This following method works if the 11 columns are side by side. Other wise you will either have to assign a manual column reference that covers your range or use a match function to match column headers over the same range.
=IFERROR(INDEX($F:$P,AGGREGATE(15,6,ROW($F$2:$F$4401)/ISNUMB‌​ER(SEARCH("225222",$‌​F$2:$F$4401)),INT((R‌​OW(A1)+1)/2))-ISODD(‌​ROW(A1)),COLUMN(A1)),"")
The reason you see me using A1 with ROW() or COLUMN() is that I am using it as a counter that starts at 1. So no real harm leaving it at F1 for row references as it is really only important that the row start at 1. conversely COLUMN(A1) can really be any row from column A as I am only interested in starting at 1. If you have to manually index because your columns are not side by side, replace COLUMN(A1) with an integer that represents the column number you want starting from the first column reference in the index range. So in the case of the formula above F:P, start counting from F.

Updated Weekly Comparison between two values

I am trying to make an excel for keeping track of body weight.
On each SUNDAY, the new weight will be inputted by the user, this will go on for an infinite amount months. I want to be able to calculate the difference between last Sunday's input and the current Sunday's input when a new weight is inputted, then display the difference in a cell.
The problem is, I can do this for the first two inputs, but I want it so once you have 4 inputs, it will no longer use the 1st two weights for the calculation, but the 3rd and 4th, and same with 8 inputs, where it would use the 7th and 8th input for the calculation instead of 1st-6th and so on.
I have tried conditional formatting and if's, although it does not get the "use newest 2" effect I want. What could I use to do this?
Make sure you have a 'spare' column to the left of your weights. Let's take column A as the spare and then record your weights in column B. Allowing for column headings and generally laying things out nicely, let's say your first weight data is in cell B4, then the following week's data is in B5 and so on. In cell A4 enter the formula:
=A3+IF(B6=0,1,0)
Now copy this formula down for as many rows as you need in column A. Your formula to get the difference between the newest two weights is:
=VLOOKUP(2,A:B,2,FALSE)-VLOOKUP(1,A:B,2,FALSE)
[EDIT - allowing for 'calendar' view]
For you calendar view you are going to need a spare row above your weight data. You could hide this row if you wanted. Allowing for blank cells between your inputs I would use a slightly different technique. In this spare row (e.g. cell D2) put the formula:
=C2+IF(D3=0,0,1)
Copy this formula all the way to the right. The formula for your newest difference calculation now becomes:
=HLOOKUP(MAX(2:2),2:3,2,FALSE)-HLOOKUP(MAX(2:2)-1,2:3,2,FALSE)
If the entries will consistently be on a Sunday and on a weekly basis and you were happy to include the date in column A and your weight in column B then keep a rolling formula in column C:
In row 5: =b5-b4
In row 6: =b6-b5
This formula in column C can be dragged down using the small box in the bottom right of the cell and will automatically change the row number for you.

Need light formula to get some counts in large data sheet

I have an employee data base that contains names and 8 movement types (Ex. Recruitment, Resignation....etc). Also I have starting head counts.
What I need to do is calculating movement counts and head counts based on the month for 12 months. Currently i am using SUMIF formula to calculate all these and the thing is excel will be very slow with all formulas. Appreciate if anyone can help me on this. See the image below for sample of the formula and I need to insert this formula in more than 600 lines.
A pivot table would be a good way to go, but by the look of your criteria you'll need to create 'helper columns' to ensure your data is ready for aggregation in a Pivot table.
For instance in your master data tab, add a new column called 'MatchesCriteria' or words to that effect, and build a formula in that column that checks for all of the criteria that you want to have the report based on, and returns a 1 or a 0, e.g.
=IF( (IF(C2="Recruitment",1,0)+IF(D2="Secondment In",1,0)) > 0 , 1 , 0)
Then run a pivot table including the 'Plant' column in your Rows, the month column in your columns and the 'MatchesCriteria' in your data values, and switch the calculation type to 'SUM' rather than 'COUNT'.
This will do the trick and will refresh in a flash compared to evaluating all of those countif statements.

Countif with dynamic headers

Good afternoon! I'm trying to get a Countifs or Index Match statement to count the number of times a value occurs in another table. The example:
On my report sheet, Column A contains 10 different statuses, such as Green, Yellow, Red etc.; Row 1 contains six dates, such as 1/31/2015, 2/28/2015, etc. These dates are calculations. The last date references my date worksheet and the five other use EOMONTH to get the month end for the five prior months.
On my data table, I have 7 descriptive columns (such as Type, Make, Model, etc) and then we begin date columns: 1/31/2010 all the way to 7/31/2015. I add a new column each month (I know, I don't like it either, but unfortunately we don't have a time series database).
What I need to do is have a Countifs or Index Match that pulls the date from my report tab, goes and finds it in the header row of my tblTrends, and then counts all those statuses that are Green, and if it's a SUV (for example).
Thoughts?
Thx!!
G
At it's most basic, you'd want something akin to:
=COUNTIFS(TypeRange,"SUV",FirstMonth,Status)
So let's say your data table starts in column L, and the first date column is O:
=COUNTIFS($L$1:$L$100,"SUV",O$1:O$100,A$2)
As you drag this formula across the different dates, it will move the date reference over one to the next month.
If you need it to dynamically determine the date column, I'd recommend OFFSET, which dynamically select a range. However, note that OFFSET is a "volatile" formula, which means it re-calculates anytime a change is made anywhere in the file, which can lead to pretty slow load times if not used sparingly.
=COUNTIFS($L$2:$L$100,"SUV",OFFSET($N$2:$N$100,,MATCH(B$1,$O$1:$Z$1,0)),$A2)
The OFFSET starts on column N, because that's the first column before the columns we want (the date columns). The MATCH tells it how many columns to OFFSET from here.
If you're going to use this over a large amount of data, then you could avoid using the OFFSET formula by creating a dynamic table. This table would only contain data for the six months you're interested in, by utilizing INDEX/MATCH, and you could run your COUNTIFS off this table, instead, using the original, basic method I first described. I can go into detail if you're unsure what I mean.

Getting average of data with multiple entries for a single date using pivot table in Excel

I have tried this, but I am unsuccessful. I have the data dump in an excel sheet (Excel 2010). The first column has month. The second has the dates. The third column has numerical data. I have applied filters on each column to get the data on the Pivot Table. There are entries for each date. There are sometimes multiple entries for a single date. Now, when I run the Pivot, I get the proper sum, but when I select average, the average is accurate only for the single entries associated with a date. I need to calculate average of multiple data entries for a single date. Here is an example:
November 11/1/13 30
November 11/2/13 25
November 11/3/13 20
November 11/3/13 25
Now, when I run the Pivot table and select to average the data, it calculates the average as (30+25+20+25)/4 = 20 (since there are 4 entries, so the sum gets divided by 4).
This is not desirable.
I require the calculation to be made as taking the 3rd and 4th entry as one for the date 11/3/13. So, the required output is (30+25+(20+25))/3 = 33.33.
I hope the example gives an clear idea of the requirement. I need a solution for this. How do we modify the Pivot so that the average is calculated not based on just the number of entries, but the average is calculated for the number of days.
Create the pivot table described by Ron (with Sum only, not Average), then copy & paste special (values) this pivot table, then pivot that for averages.
Put your dates in the "Row Labels" area. It will Sum and Average by Date
Edit: To get the average of the sum of the daily values, you can either enter an Average formula someplace for the Pivot Table Sum Column, or you could use the following array-entered formula:
=SUM(Values)/SUM(1/COUNTIF(Dates,Dates))
Where Dates is the range where you have your list of Dates (on the original data sheet) and Values is the range where you have your original list of Values.
To array-enter a formula, after entering
the formula into the cell or formula bar, hold down
while hitting . If you did this
correctly, Excel will place braces {...} around the formula.
SUM(1/COUNTIF(Dates,Dates)) will return a count of the Unique dates, so it will return 3 for the dates in question in your example.
This proposed solution uses a working column named: Value (U)
Assuming that your data is located at [B4:B8].
Add a working column at [E4:E8]
Enter this formula at [E5:E8]:
= IF( COUNTIF($C$5:$C5,$C5) > 1, 0,
SUMIF($C$5:$C$8,$C5,$D$5:$D$8) )
Then use the working column Value (U) to sum and average the values, also add Value (U) as Page Field to filter out the Value (U)=0.

Resources