Using IF with OR, AND and Wildcard in same statement - excel

I'm trying to create an IF statement that will basically look at one cell which currently has a macros enabling multi-select drop down from a lookup list.
The field the IF statement is based on is a drop down containing the following information:
Android
iOS
PC/Mac
All Devices
Mobile Devices
The user can select one value or multiple values.
The IF statement will be true IF, the field contains All Devices OR Mobile Devices OR Android AND iOS together. It must also be able to check wildcard as you can select multiple items therefore could be Android, PC/Mac, iOS in which case it should be true because both Android and iOS has been selected.
What should be the actual statement as this is the current one I'm using but I know you can't have wildcard string within this statement:
=IF(OR(C7="*-iOS*",C7="*-Android*",C7="Mobile Device",C7="All Delivery Methods",AND(C7="*-iOS*",C7="*-Android*")),"Mobile DTC/ALL","STB (VRP) HD, DEVICE (UVP) HD")
Thanks
Edit: If any of the following Scenarios is met and exist in Cell C7, then return the True statement.
Scenario 1: All Delivery Methods
Scenario 2: Mobile Devices
Scenario 3: Android AND iOS
Otherwise return the False statement.

Excel does not support wildcard statements on all formulas (see supported formulas), but you can achieve similar result, if you build a bit your formula.
Solution 1
E.g., try using FIND() with IFERROR(). FIND() will give you a number, telling you where the searched string is located.
Thus, =FIND("-Android","tell me more about -Android"), will give you a number.
If it does not find anything, it will give you a value error, which you may catch with IFERROR and return a specific value e.g. -1.
Then build the OR checking for values bigger than -1 and you will have what you need.
Solution 2
Another option is to use SEARCH(), which supoports wildcards the way you expect it:
=SEARCH("test*1";"aaaaaaaatestaaaa1")
will return 9. SEARCH in MSDN
Solution 3
In general, there are many ways to build this. As suggested in the comments by # ImaginaryHuman072889, you may use ISNUMBER(). It has the advantage, that it works quite ok with errors, thus you do not need an error catcher for it. Something like this will work ok:
=OR(ISNUMBER(SEARCH("a","b")),ISNUMBER(SEARCH("b","b")))
However, if you change the method from the first solution with an option returning 0 in case of error you would have something like this working as well:
=OR(IFERROR(SEARCH("a","b"),0),IFERROR(SEARCH("b","c"),0))
which is quite the same amount of formulas.
Solution 4
A really interesting solution, avoiding both OR() and IFERROR(), proposed by #barry houdini. It simply returns 0, if nothing from the results is found:
=COUNT(SEARCH({"a*a";"b*b";"c*c"},"I used to be abba fan."))
will return 2, because of a*a and b*b being found in abba. This is how to include the AND() of the original question of the OP:
=AND(
COUNT(SEARCH({"a*a";"b*b";"c*c"},"I used to be abba fan.")),
COUNT(SEARCH({"party*so";"am not"},"but now I am not."))
)

Related

Excel: Multiple If with Countif Statements

In Excel, I have three formulas/statements I'd like to merge into one. I've listed the statements below. Is there a way to merge all three formulas into one? I'd like to learn how to write the logic to do this. Thanks.
=IF(COUNTIF($B:$B,$A2)=1, "MATCH")
=IF(COUNTIF($B:$B,$A2)>1, "DUPLICATE")
=IF(COUNTIF($B:$B,$A2)<1, "NO MATCH")
The syntax of the IF function is IF(true-false-condition, value-if-condition-true, value-if-condition-false) (where either missing value-if defaults to 0).
3-way (or more) IF conditionals can be written by nesting multiple boolean IF's, for example:
=IF(COUNTIF($B:$B,$A2)>1, "DUPLICATE", IF(COUNTIF($B:$B,$A2)=1, "MATCH", "NO MATCH"))
Also consider good practice of trapping the default 'else' case. The above answer does not do this, and it assumes your input will always be one of your stated cases (=1, <1 or >1) so omits the final IF condition. In that example this will not error because the evaluations will always return true or false, but this may not behave as expected if an input is a different data type, null set, etc. In the stated answer, this unexpected behaviour will "fail silently" which is a potential issue.
Instead, try:
=IF(COUNTIF($B:$B,$A2)>1, "DUPLICATE", IF(COUNTIF($B:$B,$A2)=1, "MATCH", IF(COUNTIF($B:$B,$A2)<1, "NO MATCH", "ERROR")))
In implementation you would replace "ERROR" with your chosen error handling method.
You could also look at the following Excel functions, as an alternative to nesting multiple IF functions:
SWITCH:
=SWITCH(expression, value1, result1, [default or value2, result2],…[default or value3, result3])
IFS:
=IFS (test1, value1, [test2, value2], ...)
Some of these are newer than others so be sure to test to your version of Excel (and consider compatibility with any other possible users of your file).

Is there an equivalent OR logic based from a Variable value in Origen?

I am working on Verigy 93K test program and I have a logic that I would like to know if there's an equivalent code in Origen.
I am working on Verigy 93K test program and I have this logic (IF condition) that I need to insert in my flow.
Basically, I have a variable called 'INSERTION' and this will have different values like 'GCORR', 'VCORR' and others.
I would like to know if there's an equivalent code like this in Origen.
I attached a snapshot, hope that it can help clarify my question more.
In this logic, I would like to check the INSERTION value and if the value is not equal to GCORR or VCORR, the logic should pass, else, fail.
Here is the screenshot:
This pull-request adds an official API for this.
This example would be implemented as:
whenever_any ne(:INSERTION, 'GCORR'), ne(:INSERTION, 'VCORR') do
# Your tests in here
end
That would produce something logically equivalent and which can be re-targeted to other platforms.
If you don't care about that and want to produce exactly as you have it in the above example, then this should work too (where the OR is hard-coded for V93K syntax):
whenever ne(:INSERTION, 'GCORR|VCORR') do
# Your tests in here
end
Here is the preliminary documentation of this feature from the above PR - https://github.com/Origen-SDK/origen_testers/blob/66345c9422d9fa6b2577af20110259e45c2bdd26/templates/origen_guides/program/flowapi.md.erb#L71
I couldn't find api support on flow control or variable values beyond "if/unless_enable" support which can help check for 1 or zero. One way is to use render.
render 'if #INSERTION != "GCORR|VCORR" then'
render '{'
# your code for non-GCORR_VCORR flow
render "} \n else \n { \n } "

Nested If formulas in Excel

I am trying to devise a If formula in excel base on string length in test but I only return zeros. I haven't found any errors so I am requesting to insight.
=IF(LEN(B3)=4,
SUMIF(ForecastCombined!A:A,LEFT(A3,4)=B3,ForecastCombined!AL:AL),
SUMIF(ForecastCombined!A:A,A3,ForecastCombined!AL:AL))
You have two what seem to be logical tests the
"LEN(B3)=4" and the "sumif ... =B3,
if you want both to be true to continue then you need :
AND(test_1,Test_2)
if you only want one out of the two to be true to continue then :
OR(test_1,Test_2)
Can't guess more than that ...
So, this is my best guess:
=IF(AND(LEN(B3)=4,SUMIF(ForecastCombined!A:A,LEFT(A3,4)=B3),ForecastCombined!AL:AL,SUMIF(ForecastCombined!A:A,A3,ForecastCombined!AL:AL))

Trying to write an IF ( Match ); possible syntax error?

Highly likely this is a syntax error, but it's not throwing any errors.
=IF(ISERROR(MATCH(MID(Z2,28,6),$AF$1:$AG1,0)),"Mismatch","Included")
I have Z2, Z2 contains the following text:
"Revenue account for invoice P13930."
Or something like that, so the Mid function is suppoused to match that code, P13930, and not if it is within the specified cells (Here, AF1 and AG1)
I tried copying the whole text, or even just the code to AF1 and AG1, but it never writes a match. What's wrong with it?
Based it on my prototype:
=IF(ISERROR(MATCH($AE1,$AF1:$AG$1,0)),"Mismatch","Included")
Which does happen to work.
EDIT: I forgot to mention, I was wondering how to include the following scenarios:
Sometimes the code would look like this: P13930. and other times like this: P13930A. I'm not sure how to consider these as my knowledge is limited to Mid , Left , and Right. And as Jordan Mentioned, MATCH would be out of the picture given these variations.
If AF1 and AG1 contain codes like P13930A, you can use a wild card to match them like this
=IF(ISERROR(MATCH(MID(Z2,29,6)&"*",$AF$1:$AG1,0)),"Mismatch","Included")
Could you please specify your question:
First which we can advice, is to correct mid function argument:
=IF(ISERROR(MATCH(MID(Z2,29,6),$AF$1:$AG1,0)),"Mismatch","Included")
MID(Z2,29,6) - will give you result P13930
and then you want to find this code in some area, don't you? for example in the area AF1:AG1.
Please specify the result which you want to see in the cell AF2:
(a) code P13930; (b) INCLUDED - if area AF1:AG1 includes code P13930; (c) MISMATCHED - if area AF1:AG1 does NOT include code P13930 and etc.

Excel's Find function; Exceptions over values

I recently learned that Excel's Find function returns a #VALUE error when it doesn't find the needle in the haystack (i.e. no match is found). I have several questions about this behavior:
Is there another Excel function that works as Find but returns an actual value (e.g. -1) when no match is found?
Is there any well-known reason for the function having that behavior? I mean, talking about general programming and software design, Is there a known pattern (or methodology, or design philosophy) that prefers throwing exceptions over returning values (like -1, 0, "" or similar) when a function doesn't return a "valid" value?
The Find function looks for a case-sensitive match, and can be tested with IsNumber, like:
=IF(ISNUMBER(FIND("abc",A1)),FIND("abc",A1),"No exact match")
There is a very similar function called Search which does the same thing, but is not case sensitive. It also returns an error if no match is found.
So if you are looking for something and want to return -1 if there is no match and you are not worried about being case sensitive, then something like this should work for you:
=IF(COUNTIF(A1,"*abc*")=0,-1,SEARCH("abc",A1))
For case sensitive searches, it would be:
=IF(ISNUMBER(FIND("abc",A1)),FIND("abc",A1),-1)
If you are on Excel 2007 or later, you can skip the error checking by using IFERROR:
=IFERROR(SEARCH("abc",A1),-1)
=IFERROR(FIND("abc",A1),-1)

Resources