This is what my table looks like:
Please note that I cannot change the position of any data here. This is a table that will continuously expand as I add new columns to the right and new rows at the bottom.
I need a formula in Column A that will calculate the average of all data in the same row as where the formula is and the formula has to autoupdate whenever I add new columns to the right of the last column. For example, in cell A64 is the formula that will average C64 to E64. when I add new data in F64, I want A64 to autoupdate to include that new cell in the computation.
I tried
=AVERAGE(INDIRECT("C64:"&ADDRESS(ROW(),COLUMN()+4)))
but it did not autoupdate when I added new data in F64. I am not an excel expert and I mostly learn by googling, but this one is taking me forever. Please help.
This is where OFFSET and COUNTA are your friends, In A2 and fill down:
=AGGREGATE(1,6,OFFSET(C2,,,1,COUNTA(C2:XFD2)))
I have used AGGREGATE function with argument 1 for Average and argument 6 to ignore error values in the range. COUNTA resizes the array from C2 to the end of the populated area (allowing for error values).
You can also use INDEX with COUNTA
=AGGREGATE(1,6,$C$2:INDEX(C2:XFD2,COUNTA(C2:XFD2)))
Or INDEX with MATCH. In the example below, I have reduced the column end point to AA, rather than XFD (which is the last column in 2016). If you know a realistic number of columns that will ever be filled you can use that as your end point reference to reduce the amount of work your dynamic formulas are doing.
=AGGREGATE(1,6,$C$2:INDEX(C2:AA2,MATCH(99^99,2:2)))
Related
I was wondering if it is possible to make a formula that auto-adjusts its scope based on how the sheet grows. Here's an example to illustrate:
Currently, cell B16 is calculating the sum from B2 to B15. Suppose that in the future, I keep filling up the rows with items and costs and reach cell B15 (Everything is now filled up. If I want to add more items, I will insert a new row at B16 and the 'Total' Row becomes B17.
But the formula will not self adjust, and the range will remain at B2:B15. Is there a way to go about automating the process to self-adjust the formula range when I insert new rows?
I'm new to Excel, but I do have programming experience if that matters. Other alternative methods to go about solving this are also welcome. Thank you!
If it's just the sum you want to calculate, then it's fairly easy, because an empty cell is considered having value 0.
So, you can put your formula in another column and replace it by =SUM(B$2:B$1048576).
Remark:
The value 1048576 is based on my maximum number of rows. You can check that value pressing Ctrl + ↓.
If you really want to have the sum in the same column, you might use this formula:
=SUM(B$2:OFFSET(Bxxx,-1,0))
Where Bxxx is the cell reference where you are putting this formula.
I have a spreadsheet that I'm using to try and keep track of google keyword rankings, but I can't figure out how to track the last change in keyword ranking, meaning the last cell in the row MINUS the second to last cell in the row. I've included a picture on what I'm trying to accomplish. The formula would take, for example, in J3-I3 to get the last change of 4 shown in D3.
Right now I have this code:
=(LOOKUP(2,1/(3:3>0),3:3))-LOOKUP(9E+300,B3:INDEX(B3:J3,MATCH(9E+300,B3:J3)-1))
Which is fine, but I need to keep changing the cell references is. Is there any easier way to accomplish this?
You can use just INDEX(MATCH()) and refer to the full row.
=INDEX(3:3,MATCH(1E+99,3:3))-INDEX(3:3,MATCH(1E+99,3:3)-1)
If you have, say, 12 columns B="Jan" to M="Dec" with a formula in each, and you need to calculate the difference between the latest month's value and the previous month's value, the formula above does not work if any columns are blank but with formulas, or until you have a value for each of the 12 months.
If you want to calculate, say, Jun minus May when Jul to Dec are blank except for their formulas, this formula (for row 4) will do it for whatever the latest month with a numerical value is:
=INDEX(4:4,MAX(IF(ISNUMBER(B4:M4),COLUMN(B4:M4))))-OFFSET(B4,0,SUM(IF(ISNUMBER(B4:M4),1))-2,1,1)
It must be entered with Ctrl+Shift+Enter.
#ScottCraner has provided an answer with the right logic, which is to
locate the second last and last number in each row, and then perform a
simple subtraction between the two.
INDEX+MATCH is one way of solving the question, but in this case, given that all data are stored in a table, and to add the flexibility of
1) moving the table around or across worksheets;
2) entering numeric value in the same row outside of the table;
without incurring errors, I've used OFFSET+COLUMNS instead.
Please note in my example I have given a name to the table, called it Tbl_WordRk, and I have added some data (in the gray area) for testing purpose.
Basically, OFFSET works in similar logic as INDEX, with a known starting point (such as B3 in my example), it will find the value (or even a range of values) in another row or column as long as you know the relative position of the value compared to the starting point. For example, if your starting point is cell A1, the following OFFSET function will return the value in cell D8.
=OFFSET(A1,7,3) which is interpreted as 7 rows down and 3 columns to the right of cell A1
COLUMNS finds the total number of columns of a given range, which is perfect for finding a column position within a table. The following formula will return number 7 which is the total number of columns of the table in my example, but please note it is NOT the relative column position of the last column to cell B3.
=COLUMNS(Tbl_WordRk)
You need to add -1 to the above formula to find the relative column number of the last column from B3. And therefore, adding -2 will return the relative column position of the second last column from B3.
So the final formula in cell B3 in my example is
=OFFSET(B3,,(COLUMNS(Tbl_WordRk)-2))-OFFSET(B3,,(COLUMNS(Tbl_WordRk)-1))
Then you just drag it down to the last row.
Just one more advice on the conditional format of your example, I would prefer not to show a green upward arrow if there is no change in the word ranking. If you know how to edit an existing conditional formatting, here is how to set it:
Cheers :)
I need to create a function that will fill in cells Sheet2!G25:P25 according to three criteria: project type, criteria type, and date. The problem is that the criteria in Sheet 1 aren't lined up to conveniently use a VLOOKUP or INDEX MATCH. I know I'm supposed to list the formula that doesn't work but I honestly haven't even been able to get close. I've been primarily working on variations of the SUMPRODUCT such as
=SUMPRODUCT((Sheet1!A3:A19=Sheet2!A25)*(Sheet1!D3:D19=Sheet2!B25)*(Sheet1!G2:P2=Sheet2!G23)*Sheet1!G3:P19)
but that obviously won't work since the project type and criteria type aren't on the same row as the data I need. A work around I've been trying is to OFFSET the location of the cell found in the SUMPRODUCT project type and criteria type arrays but restrictions within the OFFSET function has set me back. For example, the reference section of the OFFSET function cannot be a function even if the function pulls a cell location (OFFSET(CELL("address",INDEX MATCH),0,0). The goal of this was to trick the SUMPRODUCT function into thinking that the 2 row criteria were on the same row. You guys are geniuses when it comes to this stuff so I'm sure I'm missing something.
=SUMPRODUCT((Sheet1!A3:A19=Sheet2!A25)*(Sheet1!D3:D19=Sheet2!B25)*(Sheet1!G2:P2=Sheet2!G23)*Sheet1!G3:P19)
Well, the following works for me on the basis or your example.
The condition here is that the row separation between your project and the criteria is always 4 rows apart
The formula on Sheet 2 is
{=INDEX(Sheet1!$A$1:$U$19,MATCH(1,(Sheet1!$A$1:$A$15=$A$3)*(Sheet1!$D$4:$D$18=$B$3),0)+1,MATCH(H1,Sheet1!$A$1:$U$1,0))}
This is an array formula, enter it by usind Ctrl+Shift+Enter
On sheet1 if positioned the data same as on your picture, that means the first date is in H1 on Sheet 1
The first formula entered on Sheet 2 is in cell H3
The "trick" I used is to simply offset the second search array:
Project uses A$1:$A$15
Criteria uses $D$4:$D$18
Not really an Excel user, but what seemed simple has turned out to be very difficult for me. I am in trouble as I can't come up with a nice and clean (or any) way to get it working.
What I have here:
I need to create a new columnn that would tell the amount of employees in each occupation while ignoring the duplicates (highlighted).
The amount of names formula is working, so maybe this can be used ? Or maybe it's just in the way and should be cleared.
It's just:
=COUNTIFS(A:A;A2)
Tried searching for quite a while did not find anything suitable. Any help or advice would be much appreciated. I hope I explained it in clear manner.
Thank you
Without helper columns:
Two options, D2:
{=SUM(--(FREQUENCY(IF($B$2:$B$9=C2,MATCH($A$2:$A$9,$A$2:$A$9,0)),ROW($A$2:$A$9)-ROW($D$1)+1)>0))}
Or put in E2:
{=SUMPRODUCT((($B$2:$B$9=C2))/COUNTIFS($B$2:$B$9,$B$2:$B$9&"",$A$2:$A$9,$A$2:$A$9&""))}
Notice both are array formulas and should be entered through CtrlShiftEnter
SUMPRODUCT 'Deals' in Arrays 3
You might have employees with the same name (David, Michael) in different occupations (Tech & Worker, Tech & Economy). To distinguish those from each other, in B2 you can use:
=SUMPRODUCT((A$2:A$21=A2)*(C$2:C$21=C2))
In D2 you can use:
=SUMPRODUCT((1/B$2:B$21)*(C$2:C$21=C2))
Distinct Employees Occupation Count
with a helper column
Unique and Distinct values are tricky. Using a helper column is beneficial for identifying either one of these when coupled with an expanding range:
=SUMPRODUCT((A2=$A$1:$A1)*(C2=$C$1:$C1))
Relative Rows: ^ ^
Paste to cell E2.
Copy Drag the formula down from the where pasted.
The relative row numbers identified above well increase as the formula is copy dragged down. This creates a larger and larger range for comparison. An expanding range.
In this case the range that is expanding is the range of already checked values. Many times the result range is expanded and tested against to eliminate posting duplicates of already posted results in subsequent rows of the results list.
The helper column's value is how many times the name and occupation pair has previously appeared. Zero previous appearances tells us this is the first occurance. We will only count the zeros (first occurance) in the main formula.
The main formula for counting distinct employees in each occupation:
=COUNTIFS( $C$2:$C$9, C2, $E$2:$E$9, 0)
Paste to cell D2.
Copy Drag the formula down from the where pasted.
Here we count all the rows for this row's occupation where the occupation matches the range of listed occupations and for that particular row in the list of occupations, the helper column row value is zero.
Add a final column which is the concatenation of the prior 3 columns then use
=SUMPRODUCT(1/COUNTIF(D2:D9,D2:D9))
There is a good explanation of this formula here. Basically, values that appear once will count as 1. Values that appear more than once will appear as fractions of their total occurrence count and be summed to 1.
If you convert your data to an Excel table by selecting a populated cell in the range and pressing Ctrl+T, then formulas will auto-populate down last column. You can then reference the table columns in the formula and you won't need to amend the formula as you add rows.
Looking to create a sum and a count formula that will automatically adjust itself for new rows that are inserted within the range.
For example if I have the formula in cell D55 =SUM(D17:D54). Every time I insert a new row within that range, I need to change the top range of my formula to account for it.
Is there a way to write a formula that will automatically adjust itself, so that every time I add a new row I will not need to change my summation formula?
Try
D55: =SUM(INDIRECT("D17:D"&ROW()-1))
This should dynamically adjust to added rows since when adding rows at row 17 the current value at D17 shifts to D18 and no value is present at D17. INDIRECT() should take this into account. ROW()-1 ensures that even when rows are added immediately preceding the formula these are still taken into account.
Edit: I should have added that this can be applied to any formula. Simply replace the range part of your formula with the INDIRECT.
And a quick explanation: the INDIRECT creates an Excel reference from a string so you can construct your formula using dynamic objects. The ROW part of the formula acts as the dynamic factor which is completely dependent on the row count that you add but is independent of the position at which you add your new row.
I think people are misunderstanding. You're inserting a row at the TOP of your range correct?
If so, I would suggest formatting the range as a table. That way your table could look like this:
And the sum function would be simply:
=SUM([Data])
when a row is inserted above the 7, everything is automatically updated.
You might want to have a look at this excellent link that talks about using tables to hold your ranges. This would be my recommendation ... wrap your data in a table. This will create a structured yet flexible reference.
As is noted here, and also from experience, "Because table data ranges often change, the cell references for structured references adjust automatically. For example, if you use a table name in a formula to count all the data cells in a table, and you then add a row of data, the cell reference automatically adjusts."