I am trying to write the following function in Excel.
if P2 is greater than or equal to 3 and AD2 is 0
OR
if P2 is greater than or equal to 2 and AD2 is greater than or equal to 1
OR
if P2 is greater than or equal to 1 and AD2 is 2
Then do the following:
(H2+V2)/(P2+AD2),-999)
I have had a go at writing the following to no avail.
=IF(AND(P2>=3,AD2>=0),OR(AND(P2>=2,AD2>=1)),OR(AND(P2>=1,AD2>=2)),(H2+V2)/(P2+AD2),-999)
Any pointers in the right direction would be much appreciated as I am a novice at Excel functions.
Many thanks,
Ash
Erm...
I think this is right:
=IF(OR(AND(P2>=3,AD2=0),AND(P2>=2,AD2>=1),AND(P2>=1,AD2=2)),(H2+V2)/(P2+AD2),-999)
You need to nest your different AND conditions within a OR function...
Easiest way to do it, is to have your seperate functions in a cell each and build it up a step at a time, until you're sure it's right.. Then you can paste the function into one cell if required.
Say the below are in Cells A1, A2, A3
=AND(P2>=3,AD2=0)
=AND(P2>=2,AD2>=1)
=AND(P2>=1,AD2=2)
Then your total formula in a cell:
=IF(OR(A1,A2,A3),(H2+V2)/(P2+AD2),-999)
Try this one:
=IF(OR(
AND(P2>=3,AD2>=0),
AND(P2>=2,AD2>=1),
AND(P2>=1,AD2>=2)
),
(H2+V2)/(P2+AD2),-999)
it's slightly unclear from your question what'd be the correct
AND(P2>=3,AD2>=0) and AND(P2>=1,AD2>=2)
or
AND(P2>=3,AD2=0) and AND(P2>=1,AD2=2)
but you can easily modify this behaviour in the formula above.
Related
Ok, so I am trying to do something I thought was very simple, but it is turning out to be more complicated.
What I am trying to do:
Take a value through an if statement and return 1 or 0. But I want to be able to change the formula by changing values in cells and not editing the formula itself.
Example:
cell A1 = 41%
cell B1 = >
cell C1 = 40%
cell D1 = Formula with calculation
I want to create a formula that will tell me if that 41% is > than 40%, but if I change that > in B1 for a < (in a separate cell outside the cell with the formula) or I change C1 I want it to recalculate.
I have tried the following:
=IF(A1&B1&C1,1,0)
=IF(A1&INDIRECT(B1)&C1,1,0)
=IF(INDIRECT(A1)&INDIRECT(B1)&INDIRECT(C1),1,0)
all of these result in errors and I cannot figure out how to make it work. I am assuming it is taking the > and making it a string instead of a part of the formula.
Thanks for the help.
=COUNTIF( A1, B1&C1 )
... seems to do the trick, although converting C1 to text may give some rounding errors
An alternative would of course be to enumerate all the operations:
=--IFS( B1=">", A1>C1, B1="<", A1<C1 )
And add other operators as you come across them (NB the -- turns TRUE/FALSE into 1/0)
The question is slightly confusing, so I will do my best to elaborate. I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. I would then use this number of counted cells in another equation. Does anyone have any suggestions on how to do this? I have tried using a lookup function inside of the count function, but it has not worked. This is my closest guess:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. Do I need to use VBA to make this work or should I be able to write an equation? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for.
Edit: I am adding in some sample data and expected results. I am trying to count all of the cells to the right of the "1" including the cell containing the "1". So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1"
You can use OFFSET() and MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1.
With data in A1 through J1, consider:
=10-MATCH(1,A1:J1,0)+1
In this case. 4 is the number of cells from G1 through J1, inclusive.
Assuming your range of 0 and 1 values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself.
You can use this formula:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1 appears in the last column.
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells.
To count no of occurrences in a row.
=COUNTIF(1:1,1)
If it is in a column then
=COUNTIF(A:A,1)
Hope you are looking for a countif function.
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10
I have the following formula in a cell:
=IF(Q12,ROUND(SUM(Q12:Q18)/7,2),"")
Now when I drag it down I want it to calculate SUM for Range Q19:Q25 i.e it should be;
=IF(Q19,ROUND(SUM(Q19:Q25)/7,2),"")
I believe OFFSET is the function to add in the formula but I am not sure how to do it.
You are correct, OFFSET will do this job nicely, but in writing your answer, I have had to make a consideration to the fact that I don't know what offset your formula is to the sum range!
This will do the job, and if your formula isnt in row 1, you'll need the change both of the row() - 1 statements to offset the formula back to 0 (i.e. if this formula starts in row 12, change row() - 1 to row() - 12
=IF(OFFSET($Q$12,(ROW()-1)*7,0),ROUND(SUM(OFFSET($Q$12:$Q$18,(ROW()-1)*7,0))/7,2),"")
Having said all of that, you have a conditional (=If(Q12) and a sum pointing to the same place, shouldn't you be checking Q12 for some truth, then summing?
I don't know what your data set is though, so I could be talking rubbish.
Hope this helps!
Taking only the SUM part of your formula and assuming placed in Row1 please try:
=SUM(OFFSET(Q$12,7*(ROW()-1),,7,1))
Please see my image,
I am need to count number of rows that have the cell value (in G column) = 1; but the values of column A and column B not equal another rows (not loop). For example: Row 4 have A4 = A3 = 16 and B4= B3 = 221 so we ignore (Row 6 is ignore, too).
Do you know what is the proper function ?
Thank you very much.
As per your image, use this one in I1 and drag it down:
=IF(AND(G1=1,COUNTIFS($A$1:$A1,$A1,$B$1:$B1,$B1)=1),"YES","NO")
and then in I8 you can use
=COUNTIF(I1:I6,"YES")
You can just do something like this, where you can add as many other conditionals as you need to the AND function.
=IF(AND(G4=1, NOT(A4=A3), NOT(B4=B3)),"True","False")
I'm having a little trouble following the logic in your question - the best solution is likely to write a custom VBA function and then call that function per cell. See www.cpearson.com/excel/writingfunctionsinvba.aspx
I'm relatively new to excel programming. I'm working on making a spread sheet that shows exponential decay. I have one column (A1:A1000) of 1000 random numbers between 1 & 10 using the TRUNC(RAND()*10,0) in each cell. The next Column (B1:B1000) has a logic mask =IF(A1=0,1,0) , where if the value in the A cell is 0, then the B cell shows a 1. Next, to find the number of 0's in the A column, I have the next column taking the sum of B1:B1000, which returns the number of 0's that showed up in the first column. I'm sure there's an easier way to do that, but this seems to work fine.
Here's my problem, hopefully it's clear what I'm asking:
Next, I want to take the sum of the logic column (B) from B1:B(1000- the value of the sum from (B1:1000)) in the cell below the cell that calculates sum(B1:B1000). Is there a way to to algebra in a cell formula to reference a cell? More simply, if I want to refer to A3, for example, is there a way to input something like A(2+1) to get A3? Does this make sense?
You can very easily do, in VBA:
ActiveCell.Formula = "=A" & (2+1) & "+15"
In Excel:
=INDIRECT(ADDRESS(2+1, COLUMN(A1)))+15
This will set the formula to "=A3+15". Generally, this is best done with variables, so remember to do that.
In Excel, and as pointed out by Eric, you can write the referance to the cells just like normal strings thanks to INDIRECT() function.
Just make sure that the string passed to INDIRECT() is a valid cell reference.
For example :
=SUM(INDIRECT("B" & 2+7*(H2-1)):INDIRECT("B"&(2+7*H2)-1))
Here, I sum 7 lines for each week (H2). It gives the sum of B2:B8, B9:B15, B16:B22, etc.
Hope my example will help you figure out how to use it in real situation.