IF statement to combine 7 columns - excel

I have 7 columns that have a yes or no in them (N2-T2). I need an equation that will place a 1 in "AI2" if there is a yes in any of the N-T cells. In my previous work with Excel I have only used the colon in an equation if I am adding the cells. Is this correct or does it have more use?
I tried the equation below and I get an error; #Value!
=IF(N2:T2="yes",0,1)
I also tried this one, however Excel just kept telling me that it wrong. I just tried the first two columns in this example to see if I could make it work.
=IF(N2="yes",IF(O2="yes"),0,1)

The formula you are looking for is
=IF(ISNA(MATCH("yes",N2:T2,0)),0,1)

you can use the logical OR function
=IF(OR(A1="YES";B1="YES";C1="YES";D1="YES";E1="YES";F1="YES";G1="YES");1;0)
This way you are more flexible on what you want to test (4th column "yes" OR 5th column "foo", etc.)
Likewise there is an AND(logical; logical; ...) function as well. Try to avoid cascaded IF's - they are hard to read and debug.

Related

How can I fix this Excel formula in ordert to exlude rows from calculation when two different columns has a specific value?

I am not so into Excel and I am finding the following difficulty trying to adapt a pre-existing formula to a new requirement.
Basically I have this original formula (workiong fine):
=SUMPRODUCT((D2:D7)*(B2:B7="BUY"))/SUMPRODUCT((G2:G7)*(B2:B7="BUY"))
This basically calculate an avarange price checking that the value of the B column is "BUY" (basically to exclude when the row is a SELL row). It works fine.
Now I have to change the previous formula excluding also all the row having the H column having value different from "CC". I have try in this way:
=SUMPRODUCT((D2:D7)*(B2:B7="BUY" AND H2:H7="CC"))/SUMPRODUCT((G2:G7)*(B2:B7="BUY" AND H2:H7="CC"))
Basically I tried to add an AND condition checking if the H column value is CC. But it is not working. It give me a syntax error when I try to insert this second version of my forumula.
Why? What is wrong? What am I missing? How can I fix my formula?
AND is used AND(crit1,crit2) not crit1 AND crit2.
AND will not work in this case.
Use * instead:
=SUMPRODUCT((D2:D7)*(B2:B7="BUY")*(H2:H7="CC"))/SUMPRODUCT((G2:G7)*(B2:B7="BUY")*(H2:H7="CC"))
For AND either use this logic: AND(B2:B7="BUY",H2:H7="CC") or (B2:B7="BUY")*(H2:H7="CC") in the second one * stands for AND, but as pointed out by Scott Craner in array formulas (such as SUMPRODUCT) you have to use *.

How to use COUNTIF in Excel that is dependent on two conditionals?

The first formula below is the one that operates correctly – its function is to tally up all “x’s” in a particular column when another column in that row says “Spain” and another column in that row says “Issued”.
=COUNTIFS(L$3:L$89,"=x",$A$3:$A$89,"=Spain",$H$3:$H$89,"=Issued")
The problem is with this next formula where I want it to do the same as above, plus add to it the tally for other rows that have “France”, for example. I know this formula isn’t structured correctly because the output is “zero”, when it should be “2”.
There are more countries that I want to add to this command eventually, but if I could get it to operate correctly with just two countries, adding the others should be easy. I’m not sure if the formula is the problem, or if I’m using the wrong function command, or what.
=COUNTIFS(K$3:K$89,"=x",$A$3:$A$89,"=Spain",$H$3:$H$89,"=Issued",K$3:K$89,"=x",$A$3:$A$89,"=France",$H$3:$H$89,"=Issued")
 
Something like this:
Entered using Ctrl+Shift+Enter

Excel - Formula using priority rules depending on range inputs

This is probably a simple fix (although me thinking this, means it probably isn't), so I apologise in advance if this is mere child's play.
In an excel sheet I am working on, I have a range (for the sake of this example is A1:A10) which can contain one of 3 variables (not including blanks) - A, B or C.
I require a formula in another cell to review the range in question and output a value based on the following rules in this priority:
If A appears anywhere in the column, regardless of other inputs, display A;
If B and C appear in the column, display A;
If only B appears in the column, display B;
If only C appears in the column, display C; and
If all cells within the column are blank, display blank
For rules 1-4, any blank cells within the column should not be considered. It is only where all cells are blank, i.e. rule 5, that this should be considered.
I have tried IF formulas but have found these only consider a single cell.
Also I have attempted using SUMPRODUCT along with IF but have hit a snag. The formula I used was:
IF(SUMPRODUCT(--(--(A1:A10="A")),"A",IF(SUMPRODUCT(--(A1:A10="B")),IF(SUMPRODUCT(--(A1:A10="C")),"A",IF(SUMPRODUCT(--(A1:A10="B")),"B",IF(SUMPRODUCT(--(A1:A10="C")),"C","")))))
Now I know this appears longwinded but until rule 3 it works fine. When trying for rule 4 or 5 the formula only returns FALSE
I'm all for the above formula being tweeked so that it works or for another formula entirely but I've tried searching everywhere and can't find anything on this (although this is probably down to me not phrasing my question/searches correctly).
Any help would be much appreciated. Thanks in advance!
Using your provided example, this will yield desired results:
=INDEX({"","C","B","A"},MATCH(SUMPRODUCT({3,2,1},--(COUNTIF(A1:A10,{"A","B","C"})>0)),{0,1,2,3}))
Not the easiest answer, but it works as well:
{=IF(SUM(--($A$1:$A$10="A")+(($A$1:$A$10<>"A")*(SUM(--($A$1:$A$10="B"))>0)*(SUM(--(A1:A10="C"))>0)))>0,"A",IF(SUM(--($A$1:$A$10="B"))>0,"B",IF(SUM(--($A$1:$A$10="C"))>0,"C",IF(SUM(--(ISBLANK($A$1:$A$10)))=ROWS($A$1:$A$10),""))))}
Admittedly not nearly as elegant as the above solution.

Compare 2 lists in Excel ?

I have 2 columns in a spreadsheet. One column has around 26 extra rows than the other. I've been trying various formulas to highlight or somehow indicate which columns are missing from the smaller of the lists...
I tried filling a 3rd colum with this :
=FIND(B1,A1:A1102)
which I though returned 1 if b1 was in the list a1:a1102 alas it doesn't seem to be true.
Anybody got any solutions for comparing 2 lists and isolating differences?
Thanks
To use MATCH, go with something like the following:
=IFERROR(MATCH(B1,$A$1:$A$1102,0),0)
entered into cell C1 and copied down to the end of the data in column B
This assumes that column B contains the longer list and A the shorter, of course.
The MATCH formula will return the row in which B1 is matched in A.
You can use a combination of if, iferror and vlookup functions.
=IF(IFERROR(VLOOKUP(B1,$A$1:$A$10,1,FALSE),"missing")="missing", 1, 0)
This will find matches in column A for the values in column B. If the value is missing, the iferror will report it missing (#N/A). Then the if function will output a 1 for the missing values and a 0 for those found.
EDITED:
My bad, I suggested the wrong function - except the absolute reference, you need to use MATCH - as suggested in other answers: =MATCH(B1,$A$1:$A$1102,0) or look up the whole column: =MATCH(B1,A:A,0).
Missing items will be returned as #N/A, but it easily handled with IFERROR.
I know this is a bit old, but I could not get MATCH() to work across different tabs in the same workbook. Also, I'd rather not add columns if I don't have to. What worked for me, was to use conditional formatting:
Select one column that you want to test (assume it's 'Z' for this example)
Select Conditional Formatting -> New Rule
Select 'Use a formula ...'
Use =COUNTIF('otherTab'!$A:$A, $Z1) - where 'otherTab' is the name of the other tab, 'A' is the column in that tab you want to test against and 'Z' is the column in THIS tab
Set the color scheme that something that says "I found a match!" to you
Click OK
Then you can do the same on the other column if you need to check both.
I think you need to use MATCH instead of FIND
Or if you want to be fancier about it, check out this thread:
https://superuser.com/questions/289650/how-to-compare-two-columns-and-find-differences-in-excel

Trying to improve efficiency of array formula

I have a SUM array formula that has multiple nested IF statements, making it very inefficient. My formula spans over 500 rows, but here is a simple version of it:
{=SUM(IF(IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17>0,
IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17,0))}
As you can see, the first half of the formula checks where the array is greater than zero, and if they are, it sums those in the second part of the formula.
You will notice that the same IF statement is repeated in there twice, which to me is inefficient, but is the only way I could get the correct answer.
The example data I have is as follows:
Sample Data in spreadsheet http://clients.estatemaster.net/SecureClientSite/Download/TempFiles/example.jpg
The answer should be 350 in this instance using the formula I mentioned above.
If I tried to put in a MAX statement within the array, therefore removing the test to find where it was greater than zero, so it was like this:
{=SUM(MAX(IF(B2:B6>B8:B12,B2:B6,B8:B12)-B14:B18,0))}
However, it seems like it only calculates the first row of data in each range, and it gave me the wrong answer of 70.
Does anyone know a away that I can reduce the size of the formula or make it more efficient by not needing to repeat an IF statement in there?
UPDATE
Jimmy
The MAX formula you suggested didnt actually work for all scenarios.
If i changed my sample data in rows 1 to 5 as below (showing that some of the numbers are greater than their respective cells in rows 7 to 11, while some of the numbers are lower)
Sample Data in spreadsheet http://clients.estatemaster.net/SecureClientSite/Download/TempFiles/example2.jpg
The correct answer im trying to achive is 310, however you suggested MAX formula gives an incorrect answer of 275.
Im guessing the formula needs to be an array function to give the correct answer.
Any other suggestions?
=MAX( MAX( sum(A1:A5), sum(A7:A11) ) - sum(A13:A17), 0)
A more calculation-efficient (and especially re-calculation efficient) way is to use helper columns instead of array formulae:
C1: =MAX(A1,A7)-A13
D1: =IF(C1>0,C1,0)
copy both these down 5 rows
E1: =SUM(D1:D5)
Excel will then only recalculate the formulae dependent on any changed value, rather than having to calculate all the virtual columns implied by the array formula every time any single number changes. And its doing less calculations even if you change all the numbers.
You may want to look into the VB Macro editor. In the Tools Menu, go to Macros and select Visual basic Editor. This gives a whole programming environment where you can write your own function.
VB is a simple programming language and google has all the guidebooks you need.
There, you can write a function like MySum() and have it do whatever math you really need it to, in a clear way written by yourself.
I pulled this off google, and it looks like a good guide to setting this all up.
http://office.microsoft.com/en-us/excel/HA011117011033.aspx
This seems to work:
{=SUM(IF(A1:A5>A7:A11,A1:A5-A13:A17,A7:A11-A13:A17))}
EDIT
- doesn't handle cases where subtraction ends up negative
This works - but is it more efficient???
{=SUM(IF(IF(A1:A5>A7:A11,A1:A5,A7:A11)>A13:A17,IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17,0))}
What about this?
=MAX(SUM(IF(A1:A5>A7:A11, A1:A5, A7:A11))-SUM(A13:A17), 0)
Edit:
Woops - Missed the throwing out negatives part. What about this? Not sure it it's faster...
=SUM((IF(A1:A5>A7:A11,IF(A1:A5>A13:A17,A1:A5,A13:A17),IF(A7:A11>A13:A17,A7:A11,A13:A17))-A13:A17))
Edit 2:
How does this perform for you?
=SUM((((A1:A5>A13:A17)+(A7:A11>A13:A17))>0)*(IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17))

Resources