how to restart counting in excel after meeting specific value - excel

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.

Related

Repetitive calculating distance between two values Excel

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.

In Excel, how to fill blank cells in a column, with last preceding non-blank cell in row?

I need a formula that will find the last non-blank cell in each row and use that value to fill blank cells in the same row at last column. Any cells with values in the last column will remain intact. I have not tried any formula yet. The figure below may explain better:
Normally a formula cannot refer to the cell in which the formula is. It leads to the Circular Reference error.
I am not sure if you can reach the desired result using iterative calculation (which kind of allow circular references), but the general purpose of iterative calculation is for numerical methods, not for searching for the last cell in a row :)
How are your cell values filled?
If you fill them programmaticaly, you know what is in your data and you may calculate the last column in the programmatical process.
If you fill them manually, you can live with the extra last column, which you then copy over to last column (Paste Values Only).
Or, as you properly named it in your comment, you may use the "last observation carried forward" approach:
Fill all the cells with formula "copy the value from the left".
Put your data where you do have them (i.e. overwrite the formula with actual data), leave your formula in the "empty" cells where you don't have the data.
As a result, in the last column you will have either your formula carrying the last known value, or the number you entered there.
It's difficult to give you a better advice without knowing the whole process - I still suspect a kind of the X-Y problem, you have not persuaded me enough :) It is clear that you want the last measured value, but is a self-referencing formula in the last column really the only way to achieve your goal? Cannot you look at your problem out of the box and solve it otherwise?
You can create another sheet and use something like the following to fill the blanks.
Sheet1 (Data)
A
B
C
D
E
F
G
H
I
12
14
Sheet2 (Output)
A
B
C
D
E
F
G
H
I
=Sheet1!A1
=IF(Sheet1!B1,Sheet1!B1,A1)
=IF(Sheet1!C1,Sheet1!C1,B1)
=IF(Sheet1!D1,Sheet1!D1,C1)
-> Drag till end
which will result in something like this
A
B
C
D
E
F
G
H
I
12
12
12
14
14
14
14
14
14
You could use this formula in the empty cells of column L.
=LOOKUP(2,1/(A2:K2<>""),A2:K2)
To enter it in the blank cells select column L, go to Find & Select> Go To Special...>Blanks, enter the column in the formula bar and commit it with CTRL+ENTER.

Jump to the next non-empty cell and use lates value in the list

I have the following Excel spreadsheet:
A B Desired Result Column B
1 Product A 50 **50** **50**
2 Product B =IF(A2="","",B1) 50 50
3 =IF(A3="","",B2)
4 Prodcut C =IF(A4="","",B3) 50 **40**
5 =IF(A5="","",B4)
6 ="" =IF(A5="","",B5)
7 Product D =IF(A5="","",B6) 50 40
8 Product E =IF(A5="","",B7) 50 40
** Input of User
In Column A there is a list of different products. As you can see there can either be empty cells or cells with formula ="".
In Column B I want to achieve that the last value before the first empty cell or ="" cell applies to the other rows.
For example: If I enter a 50 in Cell B1 I want to achieve that this 50 appears next to every product and empty cells or ="" are ignored.
I can achieve this with the following formula:
=IF(A2="","",$B$1)
Now the problem is, that the user can also type a different number in another cell in Column B. For example he could type in a 40 in Cell B4.
In this case I want that the 40 applies to all other following rows instead of the 50 as you can see in the section "Desired Result Column B" in the example above.
How do I have to change my formula in Column B to achieve this?
Enter the following formula in Cell B2
=IF(A2<>"",INDEX($B$1:$B1,MAX(IF($B$1:$B1<>"",1,0)*ROW($B$1:$B1))),"")
Drag/Copy down as required.
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
Try:
B2: =IF(A2="","",LOOKUP(2,1/LEN($A$1:A1),$B$1:B1))
With the addressing mode used in the LOOKUP formula, it will examine the rows up to the row before the lookup. If the column A value is not blank, lookup_vector will match the last non-blank cell in column A prior to the row containing the formula, and result_vector will return the value in the same row in column B.
It is rather critical that your user entries are restricted as you have described above.
If the user can make an entry in column B that does NOT correspond to an entry in column A, and you want that entry to be copied down, then use:
=IF(A2="","",LOOKUP(2,1/LEN($B$1:B1),$B$1:B1))
Also, note that the sequence will be upset if the user deletes an entry in column B, instead of replacing it with another number. The formulas below the deletion will interpret the deleted value as a zero.

CountIf not counting values derived from formula

I couldn't find a matching answer already but happy to be redirected!
My issue is with countifs across two worksheets but I can replicate it in a smaller environment.
I have three columns of data (A-C): -
Column D has the formula =IF(A2="Closed",C2-B2,0).
That bit works, I now need to count how many took X number of days to close: -
Column G has the formula =COUNTIFS(A2:A11,"Closed",D2:D11,F2)
Looking at the pictures 41 and 49 should have a count of 1 right? What have I done wrong? All cells are formated as numbers.
Your formula in column G uses an absolute comparison to the value in column F.
The problem is that none of your values exactly match that value.
The duration column is formatted to show a value rounded to a day, but the underlying value is not the same as what is showing in the formatted cell.
Therefore, the formula in column G needs to factor in a range of values like this:
=COUNTIFS($A$2:$A$11,"Closed",$D$2:$D$11,">="&F2,$D$2:$D$11,"<"&F3)
In words: count all the cells where column A shows "Closed" and where the value in column D is between the value in F2 and the value in F3.
You will need to add an extra value in column F for anything above your biggest number in column F.
Check you output in Column D. It must be having decimals. If that is the case, you need to round the formulas in column D using ROUND formula.
=ROUND(IF(A2="Closed",C2-B2,0),0)
Rows 4 and 7 have status as "Open" and hence won't be counted by Countifs, i. e. change value of cells A4 and A7 to "Closed" to see updated results.
Also, fix your range $A$2:$A$11, etc. when using Countifs

How to find the maximum value of a given range, dependent on the value in a separate column

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.

Resources