Excel count with fixed increment - excel

I have a large table of more than 2000 rows, and 5 columns. The values of these cells are either 1 or 0. For each column I want to be able to count the number of 1s in blocks of 20 rows starting from the first row.
Example: For each column count the number of 1s in the first 20 cells (A1:A20), then in cells 21 to 41 (A21:A41), then from 42 to 62 and so on.
Any help is appreciated.
Many thanks,
egit
I have tried various combination of COUNTIF, ROW and OFFSET but did not work. Spent sometime reading various sites for suggestions but could not find the solution.

=COUNTIF(OFFSET(A1,(ROW()-1)*19,0,20,1),1)
is used to count the number of 1s in blocks of 20 rows for column A.
The OFFSET function starts from the cell A1, which is the first cell of the first block of 20 rows.
Then it uses the ROW() function to determine the current row and subtracts 1 to start counting from the first row.
Next, it multiplies the current row by 19 to offset the range by 19 rows for each row.
This is done because the range is starting from A1, which is the first cell of the first block of 20 rows, so it needs to offset by 19 rows to look at the next block of 20 rows.
The OFFSET function then selects a range of 20 rows starting from that point.
In the first row, the formula will look at cells A1:A20, in the second row it will look at cells A21:A40 and so on.
So when you drag the formula down, it will always look at the next block of 20 rows, regardless of where you drag it.
The COUNTIF function then counts the number of 1s in the selected range and returns the result.

Related

How to fill empty cell values randomly which are sum of the last cell value?

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.

Count non blank rows in a certain range/column Excel

I want to count empty (or non-blank) rows in a given column (or range).
Example: I have a column which is spaning over 4 cells width, and each cell has either a single ''x'' or is empty. There is up to 100 rows under this column. Here's a picture to clarify:
The COUNTA() function will do that for you. For example:
=COUNTA(A1:A100)
Will return the number of non-blank cells in the range A1:A100
You can use array formula. For example, to count the first 10 rows starting from row 2.
=SUM((COUNTBLANK(OFFSET(B2,ROW(1:10)-1,0,1,4))=4)*1)
To count the first 100 rows:
=SUM((COUNTBLANK(OFFSET(B2,ROW(1:100)-1,0,1,4))=4)*1)
Use a new column to get the number of blank cells in each row, then count the number of row in this column which are equal to 4.
Or, more simply, write =QUOTIENT(COUNTBLANK(B2:E2);4) in F2, pull the cell down, then write =SUM(F2:F101) in G2.
If there is exactly 4 blank cell in a row, the F cell will have a value of 1 and the sum will just add all of these 1 to get the number of empty rows.

Excel sumif only when all are non blank cells

I have four numbers in cells A1-A4
34
45
9
18
And I want to count the sum of all four numbers:
=SUMIF(A1:A4,"<>",A1:A4)
So far so good. How do I change the formula that it only shows the total only if all the numbers (A1:A4) are present. Remove A2 for a blank cell and the total should also be blank. The group of numbers will change per column, so it won't always be four.
Consider
=IF(COUNTBLANK(A1:A4)=0,SUM(A1:A4),"")

Check if one cell of several cells on a row in Excel has length 30

I have several rows within each row several cells and I want to check if one of these cells in a row has length 30.
I tried using the LEN function, but the problem is that I have to check several cells in the row at one moment.
Excel treats TRUE as 1 and FALSE as 0. If you get an array of TRUE/FALSE values from comparing each cell in a row for a length of 30 and take the maximum, you will know if at least one cell has a length of 30.
To check A2:G2 for any cell that has an untrimmed length of 30 characters/digits put this in H2,
=AND(MAX(INDEX(--(LEN(A2:G2)=30),,)))
Fill down for subsequent rows.
To retrieve the first value that is 30 characters/digits in length put this into I2,
=IFERROR(INDEX($A2:$G2, , SMALL(INDEX(COLUMN($A:$G)+(LEN($A2:$G2)<>30)*1E+99, , ), COLUMN(A:A))), "")
Fill right for possible second, third, etc. values that are 30 characters wide. Fill down as necessary to catch subsequent rows.

Count rows until the sum value of the rows is greater than a value

I want to count how many rows have the sum value no greater than X.
Same as this Sum until certain point - MySql but just with an excel formula and only the row count.
Using the same examples as in the above, first limit should give the value 2 and the second 4.
It's easy to do by adding an extra column. In that column you would keep a running total by filling down the a formula like this
Imagining your data has a header row in row 1 and is in A1 to C6 put this in D2 and fill down
=SUM($C$2:C2)
Then in E2 put this
=COUNTIF(D2:D6,"<500")
Changing the number 500 will give you a different limit.

Resources