First post so let me say Excel is NOT my strong suit. I am trying to achieve results using IF/OR, but that may be the wrong choice. All advice and direction will be appreciated.
I have a spreadsheet. Cell F2 will always have the text "TANK" or "CYLINDER". Cell C2 will always have a number. I need to return "PASS" or "FAIL" flag in cell G2 based on the value in C2, BUT those values differ based on the text in F2.
Explanation:
IF F2=TANK & C2<=19 - return PASS,
IF F2=TANK & C2>=20 - return FAIL,
or
IF F2=CYLINDER & C2<=20 - return PASS,
IF F2=CYLINDER & C2>=21 - return FAIL,
Below is one of many options I have tried and apparently I don't know what I'm doing. Any help is appreciated...Thanks
=IF(OR(F2="TANK",F2="CYLINDER"),IF(F2="TANK",IF(C2<=19,"PASS",IF(C2>=20,"FAIL")))),IF(F2="CYLINDER",IF(C2<=20,"PASS",IF(C2>=21,"FAIL")))
I haven't tested it much, but this should be what you are looking for:
=IF(AND(F2="TANK",C2<=19),"PASS",IF(AND(F2="CYLINDER",C2>=20),"FAIL",IF(AND(F2="CYLINDER",C2<=20),"PASS",IF(AND(F2="CYLINDER",C2>=21),"FAIL"))))
Here's a working version:
=IF(F2="TANK",IF(C2<=19,"PASS","FAIL"),IF(F2="CYLINDER",IF(C2<=20,"PASS","FAIL"),"not tank or cylinder"))
However, as you've noticed, long strings of functions within functions all on one line become extremely difficult to read and debug!
You can split up the intermediate steps in your formula into seperate cells - this makes it much easier to see what's going on at a glance. For example, you could have a cell that calculates the maximum value for pass/fail:
A1: if(F2="TANK", 20, if (F2="CYLINDER", 21, -1))
A2: if(C2>=A1,"PASS","FAIL")
(the "-1" is a final "else" case, if neither "TANK" nor "CYLINDER" is true)
Other ideas: if you've got three or more cases (tank, cylinder, widget, thimble...), you can use a vlookup function to return the maximum value. See https://support.office.com/en-us/article/VLOOKUP-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1
Related
I need a formula to return the smallest unique value that meets a specific criteria, to the Nth term. Please look at image:
Goal is to have a formula in cells D2:G31 that will return the values of B2:B31 in order of smallest to largest that contain the value in D1:G1.
For example cell D2 would return 3 because it is the smallest value in the "1's" group. Cell D3 would return 12, Cell E2 would return 1, Etc...
I have tried using the code below but it just returns TRUE, I am not sure how to achieve my goal, but maybe this will help your understanding.
=AND(VLOOKUP(1,A2:B31,2),SMALL(B2:B31,1))
The AGGREGATE function provides a great method of solving this type of problem without needing array formulas. I mocked up a similar problem and used the following formula in cell E2 (dragging across and down)
=AGGREGATE(15,6,$B$1:$B$12/($A$1:$A$12=E$1),ROW(1:1))
See this answer from Jeeped for a better explanation of how it works and also an example with multiple criteria.
This array formula (click Ctrl + Shift + Enter together) should work for you.
=IFERROR(SMALL(IF($A$2:$A$31=D$1,$B$2:$B$31,""),ROW()-ROW(D$1)),"")
I use formula =SEARCH({"N.","No.","#"},D5) and it fails if doesn't fit first option "N." how can I fix it?
Using =SEARCH({"N.","No.","#"},D5) formula when you will see how the formula calculates the result using Evaluate Formula, you'll notice
evaluates to
That means formula is searching only for "N."
Therefore to search for the existence of "N.","No.","#" in a cell, number of approaches are available like:
1. =IF(COUNT(SEARCH({"N.","No.","#"},D5)),1,"")
This formula will give 1 if any of the string in the cell exists.
2. =SUMPRODUCT(--ISNUMBER(SEARCH(find_text,D5)))>0
This formula will give TRUE if any of the three string exists else FASLE.
I intend to find difference between two cells use excel formula only.
Values in two cells are separated by comma. However, there is no space near the comma.
Assume in B2, the value is
apple pie,fish,cheese
And in B3, the value is
apple pie,cheese,fish,vegetables,banana
I have to get vegetables,banana in E2
I am thinking about use EXACT function
=exact(B2,B3)
However the result returns FALSE with no doubt as those values in two cells are not match exactly.
I also think to use MATCH function but the result is #N/A.
=MATCH(B2,B3,0)
For the result, what I need is to get
vegetables,banana
Is it possible to achieve this? Grateful for your advice please. Thank you.
Reference
Find the difference between two cells
Difference between two cells in third cell
I am sorry I made mistakes in my first version in this post, I expect the result is
vegetables,banana
If in javascript, (I just use as example to show what I try to do in the excel)
I can use something like this
Array.prototype.diff = function(x) {
return this.filter(function(y) {return x.indexOf(y) < 0;});
};
//to get the result
[apple pie,cheese,fish,vegetables,banana].diff([apple pie,fish,cheese])
//the result will return
vegetables,banana
So I would like to know is it possible to use excel formula to do that? Thank you very much.
I want to get a formula with COUNTIFS, like
=COUNTIF(A1:A3,"<>"&"")
such that when A1 = 2, A2 = "", A3 = empty, it returns 1.
Notes:
A2 contains an empty string, as the result of a formula. A3 is a blank cell, with no formulas in it.
The formula posted returns 2.
I tried using various numbers of double quotes. I always get 2.
I tried using &CHAR(34)&CHAR(34). I get 2.
The solution posted in How do I get countifs to select all non-blank cells in Excel? is what I tried, it returns 2 (not useful).
The formula would actually be =COUNTIFS(range1,cond1,range2,cond2), that is why I cannot use something like
=ROWS(A1:A3)-COUNTIF(A1:A3,"") or =ROWS(A1:A3)-COUNTBLANK(A1:A3) (see this).
range1 and range2 would come from expressions with INDIRECT, but that is probably not relevant.
I have worked it out with =SUMPRODUCT(--(expression1),--(ISNUMBER(A1:A3))), but I am specifically asking about the possibility of using COUNTIFS. Discrimination of number vs. text (e.g.) is not relevant at this point.
Blank vs. Empty string is the source of "troubles" (see, e.g., this).
Excel itself is somewhat ambiguous with respect to the definition of BLANK. In my example, ISBLANK(A2) returns FALSE, but COUNTBLANK(A2) returns 1.
I am not interested in a user Function.
Use a SUMPRODUCT function that counts the SIGN function of the LEN function of the cell contents.
As per your sample data, A1 has a value, A2 is a zero length string returned by a formula and A3 is truly blank.
The formula in C2 is,
=SUMPRODUCT(SIGN(LEN(A1:A3)))
I was having this exact problem, and I just found out about the "?*" wildcard which searches for any one or more characters, thus avoiding the empty string problem--genius! See Jonathan Gawrych's answer (posted right after the selected answer) here:
Excel Countif Not equal to string length of zero
Not sure if this works for the OP, since it looks like the value in A1 could need to be handled as a number not a string, but it might help anyone else who arrived here looking for a text-parsing solution.
Is using SUM instead of COUNTIFS an option? If so, I've found it to be much more flexible for filtering data sets. For example:
=SUM(IF(NOT(ISBLANK(A1:A3)),IF(NOT(ISTEXT(A1:A3)),1,0),0))
(entered as an array formula). IF(NOT(ISBLANK(x))... filters out non-blanks, then IF(NOT(ISTEXT(x))... filters out non-text. Whatever survives the filters is counted by summing 1. You can add as many filters as necessary. If you wanted to filter out only empty strings but include other text entries you could use a filter like
IF(ISTEXT(x),IF(LEN(x)>0,1,0),0)
At first thanks to answer)) (It's important for me :p )
I have a number in A3.
When there is this number in column A (Sheet1), per exemple A7 then it will take the value of the cell B7.
=SOMMEPROD(('Sheet1'!A3:A34=Sheet1!A3)*('Sheet1'!B3:B34))
I use SOMMEPROD, it's working but only with number, and sometimes I have text and number in my cell (column B).
I already changed the format of the cell but doesn't work.
Thanks a lot)))
I think you are saying that some of the values in column B are expressed as text, not as a number, probably because they were imported from another source.
if that is the case: First, convert column B into numbers, Then, use sumproduct.
For example, FIRST convert text to values:
in C3 you would enter
=value(b3)
Then copy that down to from C3 to C34.
Then
=SOMMEPROD(('Sheet1'!A3:A34=Sheet1!A3)*('Sheet1'!C3:C34))
should have the desired effect.
Note that you sometime get #N/A errors with the "value" function, for example if there are unexpected spaces. To be safe, rather than using value alone, try this:
= iferror(value(B3),0)
or to be more creative you can try:
= iferror(value(substitute(B3," ","")),0) ' deletes all spaces
= iferror(value(substitute(substitute(b3,char(160),"")," ","")),0)
'deletes all spaces and "nonbreaking spaces" copied from a web page
It depends on what you're trying to use SumProduct for. There's two main reasons this function shows up. Those are:
To sum the product of two ranges.
To sum a range of numbers that meet multiple criteria. This relies on that True = 1 and False = 0 so when want to find the combined weight of blue dogs in some cells, your formula might look like =SUMPRODUCT(1*($A$1:$A$50 = "Blue"), 1*($B$1:$B$50 = "Dog"), $C$1:$C$50). Note the 1* which guarantees the formula will know how to multiply the results. After all, True and False don't multiply. Their binary representations (1 and 0) though, do.
NB though that people also sometimes remember it as a lookup formula because of the second use, and therefore expect to be able to get text back. Such approaches are an easy misunderstanding to end up with, but really there you want to use an INDEX(<Result Array>,MATCH(1,INDEX(1 * (FIRST CONDITION) * (SECOND CONDITION) * (AND SO ON),,),0). This approach basically gives you an array formula without CTRL-SHIFT-ENTER (it's not faster, but because the condition is in an index formula, it works), and your conditions can be arbitrary (the same way as for sumproduct). But it'll give you the FIRST result, not the sum of all of them.
Hope that helps.
Edit: Crossed my mind, you might be expecting A1 to contain Erp and B1 to contain 54, and in C1 you want Erp54. This doesn't even need a function - just the & operator, which joins two strings together - so in C1, you'd just put =A1 & B1. And you're done.