What I'd like is to have a fill down formula that looks to see when the date value changes, and sum all the previous rows for that specific date.
For example, here's a spreadsheet:
In column J, you'll see that those values are the sums of each day. Those sums should only be displayed when the date changes, and the sums will just be the sums of each specific day. I think this has to require an array formula of some kind, but any suggestions? Thanks!
UPDATE
#Scott
I should mention that the dates aren't always the same length, meaning there could have been 2 rows on one date, and 6 on another date. They are sorted, but different number of rows. So it needs to also look backwards to see where the dates change as well...
I've used the formula provided in column K, and then filled it down. The expected answer is in the column just to the right of that.
Moving my comment to an answer because I believe this works, assuming your data is sorted by date, as Scott notes:
=IF(B2<>B3, SUMIF(B:B, B2, I:I), "")
This says if the next date is not equal to the current date, sum all values for that date. Otherwise leave the cell blank.
Edit: just noting for clarity based on the comments, the formula with the given row references assumes the table in question has a 1 row header, and the formula is written in row 2 and filled down. For this question the formula goes in J2 and is filled down. Also note that if you choose to reference a specific cell range instead of entire columns with B:B and I:I, the row references need to be anchored so they don't move when filled down, for example: =IF(B2<>B3, SUMIF(B$1:B$100, B2, I$1:I$100), "")
Update #OP was looking for a forumla based approach.
Well, if the dates are sorted then it can be done with following formula in row 2 beside the Net Units column.
=IF(B2<>B3, SUMIF ($B$2:$I$50, B2, $I$2:$I$50), "")
The row numbers and columns letter should be changed to reflect the data to be selected. Missing the $ (absolute reference) will break the formula.
sumif (range, criteria, sum_range)
// Range is you area from criteria column till the sum_range column, and sum_range is the column that has numerical value to be added.
This kind of problem is best solved by using Pivot Tables. Select your data, make sure each column name/field is unique and then proceed as follows:
Go to Menu > Insert > Pivot Table
Select the cells or worksheet (new worksheet preferred) where you want the Pivot Table to be created.
In the PivotTable builder select, your Date column to Rows
Select the columns that you want to be summed up and drag to the Values Filed
Adjust the Value Filed Settings (in the Values Field list (click the drop down arrow next to each field) to SUM function. [if needed]
Viola! This should produce the desired outcome and should be the preferred method.
Related
I want to define a dynamic range that will expand the rows and columns of my range whenever a new row or column is inserted. My current formula does not want to expand to cell $T$13. My headers start in row $M$7. How can I adjust my formula?
Formula Being Used
=OFFSET(Sheet1!$M$8,0,0,COUNTA(Sheet1!$M:$M),COUNTA(Sheet1!$1:$1))
I need my range to expand to cell $T$13
Right now, your formula counts the number of text values in column M.
That is not a robust approach because column M contains only five text values, but columns S and T have many more values.
If you don't know which column may have the most number of entries, you can introduce a helper cell in each column that counts the number of entries below. I suggest you insert a new row 2. In column M, for example, put a formula in M2
=counta($M$3:M$99999)
Copy that formula across to column T.
Next you can evaluate which of the columns has the largest number
=max(M2:T2)
This can be plugged into your original formula like this:
=OFFSET(Sheet1!$M$8,0,0,max(M2:T2),COUNTA(Sheet1!$1:$1))
So now, instead of just looking at how many rows are in column M, the formula uses the maximum number of rows in the columns M to S.
You can now hide row 2 if it upsets your worksheet design.
Edit: the mere count of text values with CountA will ignore blank cells and will return incorrect results. You really need a formula to find the row number of the last populated cell in each column.
This should really be a new question, but here goes
If the column has number values you can use
=MATCH(99^99,B5:B999,1)
If the column has text values you can use
=MATCH("zzz",C5:C999,1)
Adjust your ranges accordingly.
I ended up using the solution mentioned by #tevlyn.
In range$M2:$T2
I have the follolwing formula =IFERROR(MATCH(99^99,M$8:M$999,1),0).
I've added IFERROR because my data doesn't always have data stretched to $T2.
I then defined my range in name manager using:
=OFFSET(Sheet3!$M$8,0,0,MAX(Sheet3!$M$2:$T$2),COUNTA(Sheet3!$1:$1))
This still works even if there are blanks in between the range.
I have a work sheet in which there are several cells with a specific entry - let's say "A". These are not all in the same rows/columns. After each cell is a date.
I need to count the number of cells containing "A" which also have a specific date in the cell immediately to its right. I've tried combinations of Countifs and Indirect, with no success. How can I achieve this?
This counts the number of times that there is A in column A and 1 in column B
=SUMPRODUCT(($A$1:$A$5="A")*($B$1:$B$5=1))
This outputs in cell D1
Not too difficult.
I have created a sample sheet with 8 rows and 5 columns of data.
See below, the formula in cell C12 counts the number of occurrences where the a cell with a date of October 31, 2017 is directly to the right of a cell that contains the text A.
If you want more info as to how this works, read on:
When searching for cells that contain A, you don't search in the last column of the data (in this case, column E) because it is impossible for a column to the right to have any date in it. This is why a portion of the formula says A1:D8="A" instead of A1:E8="A". This is the same reasoning why we start searching for a date in column B rather than column A in the formula.
You can achieve this with a helper row. Add additional row on top of your Worksheet. In cell "A1" enter formula below.
=COUNTIFS(A2:A2000,"A",B2:B2000,"YourDate")
Drag this formula to the rightmost of where you have data, then simply sum all values returned by formula.
I am trying to display the total sum of all the numbers for a particular column. I want the sum to be displayed above the column as follows:
21 30
A B
6 5
6 10
6 10
3 5
I know I can sum the values and display it at the bottom of the column using =SUM(A3:INDIRECT("D"&ROW()-2)), however I am not getting a way to display it at the top of the column.
Please guide.
Based on the comments and the previous answers I suggest following formula, entered in cell A1:
=SUM(OFFSET(A$2,0,0,ROWS(b:b)-1))
You can then copy/paste to the right till second last column.
You could also modify your formula in A1 like this to achieve the same:
=SUM(INDIRECT("A2:A"&ROWS(A:A)-2))
But then you cannot copy/paste to the right...
A more general approach with your idea would be:
=SUM(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROWS(A:A),COLUMN())))
You can then copy/paste to the right till last column.
Some explanations:
Both formula sums up every value in the range from A2 till the bottom of column A (i.e. for Excel 2010 this would be A2:A1048576)
It doesn't matter if there are blanks or cells without value; the formula sums up only the numbers
I put A$2 and B:B in the OFFSET formula to avoid circular references, since I'm writing in cell A1 and I cannot write A$1 nor A:A
With the INDIRECT formula you don't have to worry about circular references
Further commenting (sorry, I don't have the credits to comment at the right place under the question):
Phylogenesis formula =SUM(A3:A65535) could also do the work, isn't it?
Didn't understand your question at first, because you talk of "sum of all the numbers for a particular row" but then you sum columns, isn't it?
When I'm doing something like this, I prefer to not include any empty cells beneath the range I'm summing, because I've had errors in the past as the result of including them (usually because there's a cell way down in the column somewhere that I'm not expecting to have a value). I'm assuming that A & B are your column headers. Assuming that, here is how I would do it. This is your formula for cell A1:
=SUM(OFFSET(A$1,2,0,COUNTA(A$3:A$65535)))
Explanation
I'm updating this with a brief explanation, per the OP's request.
According to ExcelFunctions.net:
The Excel Offset function returns range of cells that is a specified number of rows and columns from an initial supplied range.
The function reference for OFFSET is:
=OFFSET(reference, rows, cols, [height], [width])
What this formula does is create a dynamic range based on the number of cells in the selection, relative to cell A$1. This is an offset of two rows and no columns, which starts the range at A$3. The height of the range is the total number of filled cells in the range A$3:A$65535. The assumption here is that there are no blank cells in the range, which there were not in the sample data.
I use excel 2007
i made a table with few columns but too many rows. Each row contains some data and simple formulas.Now I want to duplicate a specific row based on current date [TODAY()] at top of the sheet.I mean whenever I open the file,the right row according to computer date,be shown directly at somewhere else instead of looking through all rows to find it.
thanks
above your table. add an empty row.
First column add =TODAY() // This will show todays date in the column and can be used in your other formulas. We will assume the cell is A1
Second Column add = VLOOKUP($A$1,A2:D8,2,FALSE) A1 being the date, A2:D8 being the table range (A2 top left cell, D8 bottom right cell), 2 is the second column of your table range, false returns the value in the second column as longs as the date (A1) matches the date in the first column on your table range.
Copy the formaula across the columns, changing the lookup column in the formula. ie. Third column VLOOKUP($A$1,A2:D8,3,FALSE)
Glad to help.
I am working with Microsoft excel 2010. I have different dates like column E1:E19 that are not in specific interval. I want help to find only starts month date and paste them into G column like shown into the figure.
First of, is to say - both K_B and Ibrahim Odeh have valid and good attemps. I just want to add another option, because those options use additional rows or manual tools.
Here is the formula I came up with to solve this as shown in your screenshot - just one column, just the rows with the starting dates:
G1=SUBTOTAL(5,E$1:E$19)
G2=SUBTOTAL(5,OFFSET(E$1:E$19,MATCH(EOMONTH(G1,0),E$1:E$19,1),0,ROWS(E$1:E$19)-MATCH(EOMONTH(G1,0),E$1:E$19,1)))
It is possible to use this for the whole column, like this:
G1=SUBTOTAL(5,E:E)
G2=SUBTOTAL(5,OFFSET(E:E,MATCH(EOMONTH(G1,0),E:E,1),0,ROWS(E:E)-MATCH(EOMONTH(G1,0),E:E,1)))
And now, some explaining:
First, you need a starting point in G1 - so we use SUBTOTAL to get the earliest date in column E, using MIN (which is 5).
Now we work from here, by offsetting the range which we use to calculate our SUBTOTAL, still using MIN (5), to get the beginning of each month.
The trick is OFFSET. The first parameter is out basic range, which we will offset, then we have to determine how many rows to offset, and to not get an error, we use ROWS(basicRange) - rowOffset to always stay in out range.
MATCH is used to determine the necessary offset, by looking for the row of the last listed date of the month from G1 using EOMONTH.
Hope this clears any question.
Edit:
Because I do have to translate this, here is the original:
=TEILERGEBNIS(5;E:E)
=TEILERGEBNIS(5;BEREICH.VERSCHIEBEN(E:E;VERGLEICH(MONATSENDE(G1;0);E:E;1);0;ZEILEN(E:E)-VERGLEICH(MONATSENDE(G1;0);E:E;1)))
as long as your dates columns is sorted as it looks in the example then do the following:
insert a row above row 1 (for use of the formula)
enter a formula in column A in all rows that your table has. The formula reads:
=If(NOT(YEAR($E2)&MONTH($E2)=YEAR($E1)&MONTH($E1), MAX($F$1:$F1)+1, "")
This will add increasing numbers from 1 to the number of months involved only next to the first date in your table for that month.
Then in your table in column G put:
=VLOOKUP(ROW(), A:E, 5)
you can drag this formula down as far as you want. The formula finds the first record in A:E that matches the row number in G (ROW() in G1 returns 1), Then VLOOKUP() will return the value in the 5th column in A:E (which is column E with the date).
The Formula in column A should be to the left of the dates for the VLOOKUP() formula to work.
Alternatively you can put it in a column to the right but then use another formula in stead of VLOOKUP() in column G:
=SUMIF(F:F,ROW(),E:E)
This sums all values in E for rows where the value in F matches the row number of the cell in G.
I think you need to use analysis-toolpak Add-on to perform this task:
check out the following URL if you need to know how to load it:
http://office.microsoft.com/en-us/excel-help/load-the-analysis-toolpak-HP001127724.aspx
Regards