In a single binary column, made up only from 0 and 1 (011111011110101111011), I want to calculate the distance between zeros (as shown in the following image), or to count the amount of consecutive 1 in the column and restart the counting as soon as a 0 comes up in the list.
Can someone please give any idea which formulas to combine?
I can get it to calculate the first group, but as soon as the second 0 shows up, I don't know how to restart counting from that point.
Well, you can test this, but it gives the count in the cell next to the zero...
=IF(A2=1,"",ROW()-COUNTIF(A$1:A2,0)-SUM(B$1:B1))
So, it might just be a start for you to edit as you need.
Whenever I need to do something like this, I use two additional columns.
In the column next to the data (i.e. B) enter 1 in the top cell (B1).
In the rest of the cells in column B enter the formula (here for cell B2):
=IF(A2=A1;B1+1;1)
This will add 1 to the previous number if there is a 1 in column A, and otherwise reset the count to 1, so it keeps track of a running total of the number of consecutive 1's (or zeroes for that matter).
Now in Column C, add the following formula in all the cells (hier formulated for cell C1):
=IF(AND((A1=1);(A2<>1));B1;"")
This simply checks if it is the last 1 in the series and copies the value from column B, or else returns an empty string. The result looks like this:
The
Then you can hide column B to only show the result in column C.
Related
In the below image I want to repeat the counting after it reaches 100 in a cell or shows zero and again starts from 20.i.e based on quantity.
If I give 1 in the D column then it multiplies 1*20 and gives 20 In the E column. similarly, it continues but when it reaches 100 it should rest or start counting from 20 from the next cell plz help me.
I think I need some more information on column E's formula. It looks like you are not just multiplying column D by 20 to get column E, because 1*20 doesn't ever equal 40 or 60 or 80.
My guess is that your formula for column E is, for example:
=D3*20 + E2, or in other words, multiply 1*20 and add the previous cell from column E.
If that's what you're doing, then try the below formula, which changes how a cell in column E is populated depending on what the value of the previous cell is:
=IF(E2<>80,D3*20+D2,0)
You'll need to set that formula in E3.
These are the formulas you need:-
[E2] =MOD(SUM(D$1:D2)*20,100)
[F2] =IF(E2=0,"PAY","PAID")
Copy both down as far as you require.
thank you for taking the time to look at this question.
I'm looking for an equation that can easily take the numerical values from Sheet 1 (the first picture) which has 2 blank cells in between values for four values and then has 4 blank cells and then the other four values. I'm not sure if I am making sense but hopefully the picture I have attached helps.
Notice 2 blank rows between first 4 rows with values (Rows 2-11) and same between rows 16 and 25.
Also notice the 4 blank rows between the two sets of values.
For me, this is repeated for 700 values, same set up of 2 blank rows for 4 sets of values and then 4 blank rows and then four sets of values with 2 blank rows. I'm sure there is an easier way to do this.
I'm trying to recreate Sheet 2 from Sheet 1 using an equation. Is this possible?
Apologies in advance, English isn't my first language.
If the numbers are going to start in B2 and the intervals and offset staggers are static then,
=INDEX(B:B, 2+(ROW(1:1)-1)*3+INT((ROW(1:1)-1)/4)*2)
If the first number is in S6 then,
=INDEX(S:S, 6+(ROW(1:1)-1)*3+INT((ROW(1:1)-1)/4)*2)
Put this in D2:
=IFERROR(INDEX(Sheet1!B:B,AGGREGATE(15,6,ROW(Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A)))/(Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A))<>""),ROW(1:1))),"")
And copy down till you get blanks.
This will return the numbers in order that they appear on sheet 1.
The Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A)) set the data set bounds. This being an array type formula it needs to reference the smallest possible data set. This part finds the last cell in Column A and sets that as the extent of the data set so we do not do unnecessary iterations.
The MATCH part will return the last row that has text in it, if Column A has numbers then we need to change the "ZZZ" to 1E+99 to get the last row in column A with a number.
The AGGREGATE is working like a small in that it will create an array of row numbers and Errors. It will return ROW Numbers where (Sheet1!$B$2:INDEX(Sheet1!B:B,MATCH("ZZZ",Sheet1!A:A))<>"") return true. And an Error where it returns FALSE.
The second criterion 6 in Aggregate tells it to ignore the errors, so it is only looking at the returned row numbers.
The ROW(1:1) is a counter. As the formula is dragged down it will iterate to 2 then 3 and so on. This tells the Aggregate that you want the 1st then the 2nd then the 3rd and so on.
The chosen row number is then passed to the INDEX and the correct value is returned.
If your numbers are in order (smallest to largest like your example) or you want the output in order(smallest to largest) then you can use this simple equation in D2:
=IFERROR(SMALL(Sheet1!B:B,ROW(1:1)),"")
Then copy down till you get blanks.
Here is another formula you might use.
=INDIRECT(ADDRESS((INT((ROW()-ROW($A$2))/4)*14+ROW(A$2))+(MOD(ROW()-ROW($A$2),4)*3),COLUMN($A$2),1,1,"Sheet1"))
You can paste it to the first cell where you want the result and copy down.
Note that $A$2 is the cell from where all the counting starts. If your data start from A3 you can change the references accordingly. Note further that ROW($A$2) is long for 2. I chose this syntax to enable you to identify the meaning.
COLUMN($A$2), on the other hand, just identifies Column A as the source of the data to be lifted. Row 2 in this formula is insignificant. It's the A that counts. However, COLUMN($A$2) is long for just 1, meaning column No. 1, meaning A. Once you get your bearing in the formula you can replace COLUMN($A$2) with 1.
Screenshot of the Excel worksheet
I'm working with historic stock prices, and using eight columns I have:
Column A: High
Column B: Low
Column C: Close
Column D: Cx-Cx-4
Column E: Counts the number of consecutive positive numbers in column D
Column F: Counts the number of consecutive negative numbers in column D
Column G: Calculate the difference between the maximum of column A and minimum of column B within a given sequence.
As an example G1 should equal:
=max(A1:A5)-min(B1:B5)
G6 should equal:
=max(A6:A8)-min(B6:B8)
G9 should equal:
=max(A9:A11)-min(B9:B11)
And so on.
I'd like to know if it is possible to automate this calculation, possibly with the use of one or more additional columns.
Welcome to SO!
This may not be the most efficient solution as you need to add two helper columns, but if I understand your requirements correctly, then this idea should work well enough.
First, let's assume that there are 100 rows in your data set. Given that, enter the formula "=A100" in cell G100 and the formula "=B100" in cell H100. This sets up the boundary condition for the formulas in columns G and H. Now, in cell G99, enter this formula:
"=IF(E99="",G100,IF(E100="",A99,MAX(A99,G100)))"
What this formula does is set up a "running maximum" with the following logic:
If the cell in E99 is blank, copy the running maximum from G100, else:
If the cell in E99 is not blank but the cell in E100 is, set up a new running maximum from the cell in A99, else:
Take the maximum of A99 and G100 as the new running maximum.
Similarly, copy the following formula into cell H100:
"=IF(F99="",H100,IF(F100="",B99,MIN(B99,H100)))"
This follows the same logic as the previous formula, but takes the minimum of column B.
Copy or autofill these formulas to the top of the data set. This should now give you running maximum for column A and a running minimum for column B.
The next step is to calculate the difference. I notice from your question, that you only seem to be interested in calculating this difference at the top of each range (G1, G6, G9, etc.), rather than doing it in every row. Given that, we need a slightly more complicated formula.
The boundary condition for this formula is simply "=G1-H1" entered in cell I1. In cell I2, enter this:
"=IF(OR(AND(E2<>"",E1=""),AND(F2<>"",F1="")),G2-H2,"")"
How this works is that it check two conditions that indicate a range boundary:
E1 is blank and E2 is not
or
F1 is blank and F2 is not
If either of these conditions hold, the IF statement is true and "G2-H2" is diplayed, otherwise a blank cell is displayed. Now copy or autofill this formula to the bottom of the data set.
As a final step, you can now hide columns G and H if you don't need them displayed. This should now give you the results I think you're looking for. Please let me know if this doesn't work out for you.
Column "A" is a numbering column for each Row, some numbers are the same, ie..
A1 is 1
A2 is 3
A3 is 1
A4 is 3
I need a formula that will show how many cells with content are in this column without counting duplicates, as above would be 2. I was figuring an "If-Then" formula but am unable to get it straight. Any help out there? Thank you in advance!
If you're using Excel 2013, I want to say that there's a count distinct function. Nonetheless, you can do it like this:
=SUM(IF(FREQUENCY(A1:A4,A1:A4)>0,1))
EDIT: Adding an explanation. The FREQUENCY function gets the frequency of the unique values within the array A1:A4 (first parameter), binning it using the values within A1:A4 (second parameter). The IF checks to see if that returns anything, i.e. if the frequency is greater than 0, in which case it returns 1 for each unique value it finds. Then the SUM adds the number of 1s returned by the IF statement, in turn giving you the number of unique values within the array A1:A4.
I have a table set up as follows:
Column 1 - Customer Name
Row 1 - Item Name
Row 2 - Item Cost
Row 3+- Item Quantity
How do I set up the last column to calculate the total cost for each customer? I.e, For each customer row, I want to multiply the number in each cell (= quantity) by the corresponding cell in Row 2 (= cost), and add them all up for the final bill.
To clarify what I'm saying I'm attaching the following picture so that we can discuss specifics.
Have you tried SUMPRODUCT - it does exactly what you need, gives the sum of 2 or more multiplied ranges?
=SUMPRODUCT(A71:C71,$A$2:$C$2)
You can extend the ranges as far as you need. If you want to add columns make sure you don't add at the end, e.g. if you retain one blank column (D currently) and include that in the formula, then if you add a column at D the formula will automatically extend to E
You can use sumproduct but specify the ranges, e.g. =sumproduct(B2:B6,C2:C6), the next row would then be =sumproduct(B2:B6,D2:D6) etc. I'm sure there's a way to "fix" your cost row but it's quite quick doing it this way
If, for example, your first data set is in column A (i.e. per unit cost) and the second data set is in column B (i.e. quantity), and you want the total cost for each item for the specified quantity, place the following formula in C1
=A1*B1
Select C1 and drag the fill handle - this is the small
black square at the bottom right corner of the cursor as far down the column as you need. The program will automatically replicate the formula with the correct cell numbers for each row.
One way is to use this formula:
=SUM(B4:B5)*B2+SUM(C4:C5)*C2
It is not so cool but you still need to expand the formula even with SUMPRODUCT because the range has to be the same as far as I know.
The other way I came up will use a matrix function called MMULT and here is the example:
With this array (means you have to click Ctrl + Shift + Enter altogether) formula entered into cell D6: =SUM(MMULT(B2:C2,TRANSPOSE(B3:C5))), you will get your expected result without needing all the subtotals. Please note this is a 2 x 1 By 2 x 3 Matrixformula.