I am trying to figure out how to count the last 10 cell values that are bigger than 1, in a given range, and to exclude blank cells. The formula should handle last 10 non-blank entries dynamically in a column.
I have this array formula from another forum:
=IFERROR(AVERAGE(IF(ROW(A2:A20)>=LARGE(IF(A2:A20<>"",ROW(A2:A20)),MIN(COUNT(A2:A20),10)),IF(A2:A20<>"",A2:A20))),"")
It averages the last 10 cell values, excluding blanks.
I have tried to replace the "average" function with "countif", and I added ">1", but without success,it returned zero.
The problem with your question is that you only need last 10 cells of your range. Assuming your range is A2:A20, you count the last 10 values greater than 1 as follows:
=COUNTIF(OFFSET(A2,ROWS(A2:A20)-10,0,10,1),">1")
Note that you have to type in the first cell of the range (A2) as well as the whole range (A2:A2O) and you have to type number 10 twice, but that's how Excel programming is...
Made some changes in your formula:
=IFERROR(SUM(IF(INT(IF(ROW(A2:A20)>=LARGE(IF(A2:A20<>"",ROW(A2:A20)),MIN(COUNT(A2:A20),10)),IF(A2:A20<>"",A2:A20)))>1,1,0)),"")
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
Instead of COUNTIF function, I am using SUM(IF()). For deatils see this.
Here, INT function converts False to 0 and TRUEto 1.
Related
I have a value in 11th cell as 35. From 1st cell to 10th cell is empty. I want to fill 1st cell to 10th cell randomly and its sum should be equal to to 11th cell as per in figure. Cell 1 to 5 should have the values between (0-2) and Cell 6 to 10 should have the values between (0-5). Rows 1,2 and 3 filled by manually. I need formula for row 4 which satisfies the conditions and sum should be equal to 20. Guide me the formula in excel, libre-office calc or python. Thanks.
The meaning of the task is not very clear (in fact, why not just fill ten cells with the value 2 and get the desired 20?).
However, the task is not very difficult to solve: The first five cells are filled with =RANDBETWEEN(0;2).
When calculating each next value, you are guided by the already accumulated sum of the previous cells SUM($A1:E1) - that is, fill the next four cells with
=MIN(RANDBETWEEN(0;$K1-SUM($A1:E1));5)
The tenth cell is calculated as the difference between the expected number and the already accumulated sum of the nine previous cells =K1-SUM(A1:I1).
Your screenshot does not show the column names and row numbers - I gave formulas for the range A1:K1, you should adjust them according to your data.
So I got the basics of the formula down, but it doesn't shift when I input new numbers.
The formula takes the last six numbers in the row, excluding blank cells, and sums them. I'm looking for the summation to change, but keep the previous calculations.
Here it takes the last six and changes all of them. This is tough because it involves noninputs for some cells. Here's what I have. The 43 is in cell B7 for reference. The initial summation formula is
=IF(H$7<>"", SUM(OFFSET($B$7,0,COUNT($B$7:$AA$7)-1,,-6)), G$6)
Any quick fixes to the formula that I can do? Remember that there is a possibility of blank cells in the future (beyond when 41 is entered).
To sum the last 6 non-blank entries in a row, you can use the non-volatile formula:
=SUM(INDEX(B1:XFD1,-1+AGGREGATE(14,6,1/ISNUMBER(B1:XFD1)*COLUMN(B1:XFD1),{1,2,3,4,5,6})))
Assumes formula might be in A1
If formula not in the same row as the range to be summed, you could use a whole row reference (eg 1:1)
Note the -1 in the columns argument
This compensates for the difference between the INDEX into the array and the column number. Since the array starts in Column B (2nd column) we need to subtract 1.
If the array started in Column E (5th column) we would need to subtract 4.
If the array referred to the entire row, there would be no need to subtract.
If there are less than six numbers, the formula will return a #NUM! error. You could compensate for this by wrapping the formula within an IFERROR function, or you could test specifically with COUNT(arr) > 5
In my excel template, I need to have a formula to multiply two numbers with 2 or 3 conditions, and then sum the found numbers in an area.
For example;
First range is; AI22:AI1100
Second range is; AB22:AB1100
Third range is; N22:N1100
Fourt range is; K22:K1100
For first formula, i need to check the second range, found the cells that contain the same value as A2, then get the row number, find the value of the first range/that row cell, then divide it to its fourth range, and go on like this till AB1100 and sum all of that found numbers.
For second formula, i need to check the second range, found the cells that contain the same value as A2, then get the row number, check the third range if its the same value as A3, if it is then find the value of the first range/that row cell, then divide it to its fourth range, and go on like this till AB1100 and sum all of that found numbers.
I tried those with sumproduct, but it only sums both ranges and divides them in the end.
I can write this in Vba, but I need to store the values in the worksheets, so it will be better if I can do this in a formula.
I am open to suggestions.
You want SUM() as an Array formula
=SUM(IFERROR((AB22:AB1100 = A2)*(AI22:AI1100)/(K22:K1100),0))
And:
=SUM(IFERROR((AB22:AB1100 = A2)*(N22:N1100 = A3)*(AI22:AI1100)/(K22:K1100),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when Exiting Edit mode.
I am trying to get year to desired month total of personal expenditure sub categories. After researching stackoverflow, I found a formula seemingly appropriate for my requirements. I found it shifting the desired area by one row down during formula evaluation. I modified the formula by hit and trial on adhoc basis which is giving the correct results. To me the initially chosen formula appeared quite appropriate. I have shown below the sample data sheet and the evaluation steps of the original and modified formula. Could someone explain particularly the offset portion as to why it was going wrong for the initially chosen formula and how the modification helped in solving the problem. Somehow I am not able to get conceptual clarity on this issue.
Sample Data files
Personal_Accounts evaluated with formula A
Personal_Accounts evaluated with modified formula
Offset works by specifying:
A cell from you which you will offset (A1 in this example) then specifying how many rows and columns to move from that position, and then how tall and wide to make the range.
The number of rows to move down: In this case the number of rows down is determined by Match(). Match() here will return the number of rows down in the range A1:A9 that the value SS can be found. The answer is 5. Offset now is looking at Range A1 + 5 rows: A6
The number of columns to move across: Here we move 1 column. No funny business. New range is B6
The number of rows to include in the range from that start point: Here COUNTIFS() is used to return the number of times SS is found in the range A2:A9. The answer is 3. So the range will start at B6 and include three rows down in the range. Essentially B6:B8.
Finally, the number of columns to include in the range: Here it's 7 since that's what you have in cell A13, so your range is now B6:H8
OFfseT() returns that range and Sum sums it up
You subtracted one from the results of MATCH() and correctly moved that formula to produce B5:H7. You could have also changed the search range in MATCH() to A2:A9, which would probably make more sense from a readability standpoint.
Lastly, your COUNTIFS() could just be COUNTIF() since you are not evaluating multiple conditions.
So if I had to write this from scratch, I would use:
=Sum(Offset(A1, Match(A2:A9, A12, 0), 1, Countif(A2:A9, A12), A13)
Which will get you the same correct answer, without any math on Match() results.
Offset has two main functions - either to move to cell (target) using specified number of rows and columns from the starting point, or to select range of specified number of rows and columns starting in the target cell. Your original formula has issue in this part
MATCH(A12;A1:A9;0)
matched cell is fifth therefore the offset moves 5 rows down ending in A6, because it starts in A1 + 5 rows. Then it moves 1 column to be in B6 and then creates range of 3 rows in total and 7 columns = B6:H8. So you need to deduct 1 from the result of the match function to end up in the right row.
For better understanding imagine if the SS value was in the first row of the range A1:A9 (in A1) - then the offset would move from A1 one row down to A2 although you wouldnt want it to move at all.
look at your basic offset formula definition.
Offest (REFERENCE CELL, HOW MANY ROWS TO MOVE FROM REFERENCE, HOW MANY COLUMNS TO MOVE FROM EFERENCE, HOW MANY ROWS TO RETURN, HOW MANY COLUMNS TO RETURN)
so if you set your reference cell to A1 and you want to return the result in A2, you need to move down 1 row from your reference cell.
OFFSET ($A$1,1,0,1,1)
Now if we look at the match portion of your equation, MATCH return what position the information is in. So if we want to find the match position of the information in A2 in a range going from A1:A100, Match is going to tell you that the information in A2 is in the 2nd position of the column. Or more precisely it returns a value of 2.
So now we need to tell offset how far down to reach the 2nd position. We dont actually want it to move down 2 rows to get to the second position since our reference point is A1 which is the first row. As a result we really want to go down 1 row to get to the second row. So you want 1 less from your match results which you correctly did by doing Match(...)-1
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.