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))
Related
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).
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."))
)
I am constructing a nested IF statement, and I believe I am missing an ELSE but I cannot figure out where. I have the following statement:
=
IF(AND(B2="4",E2="R37",X2="Y"), "Non-Competing",
IF(AND(B2="4",E2="R37",X2="N"), "Competing",
IF(AND(B2="4",E2<>"R37",RIGHT(Z2,2)="00"), "Non-Competing",
IF(AND(B2="4",E2<>"R37",RIGHT(Z2,2)<>"00"), "Competing",
IF(B2<>"4","-")))))
I thought the last bit would cover the rest, but I am receiving a FALSE when I was hoping to get a result. For example, when B2=4, E2=R37, and X2=Y, I am expecting "Non-Competing" but am receiving FALSE. I also tried a combination with OR:
IF(OR(AND(B41="4",E41="R37",X41="Y"),
AND(B41="4",E41<>"R37",RIGHT(Z41,2)="00")), "Non-Competing",
IF(OR(AND(B41="4",E41="R37",X41="N"), AND(B41="4",E41<>"R37",RIGHT(Z41,2)
<>"00")), "Competing",
IF(B41<>"4","-")))
...which gives me the same result.
Any assistance would be greatly appreciated!
The missing else is in IF(B2<>"4","-"). You need IF(B2<>"4","-",<whatever last-ditch-answer>) If you are reaching False, then B2 is 4, but none of the other full conditions were met.
Without seeing your data, I can't know for sure, but I'm guessing that you may have intended that entire statement to behave as an else. If that is case, I would replace IF(B2<>"4","-") directly with "-".
Is it possible to use an IF statement for multiple criteria? or what would I be best using... I have tried to amend the question with what I'm looking to do the code isnt correct in this but it may highlight more what Im looking to achieve.
If(A3="Dog","Dog Green","Dog Blue"),Matches,doesn’t match)
For some reason it wont let me upload a picture....
Any help/advice would be greatly appreciated
This will definitely work:
=IF(OR(A3="Dog",A3="Dog Green",A3="Dog Blue"),"Matches","doesn’t match")
just ad OR statement inside IF Statement
Don't forget to use Quotation marks also
There are many ways to test for multiple criteria in Excel. Probably the easiest would be either to:
Use the AND / OR BOOLEAN operaters. AND(test1,test2...) checks to see whether each of test1 & test2 are TRUE (can hold as many arguments as you need). ie:
=if(And(A1="dog",B1="cat"),"there is a cat and a dog", "there is not both a cat and a dog")
OR(test1,test2) checks to see whether either test1 is TRUE, or test2 is TRUE, or if both are true. ie:
=if(Or(A1="dog",B1="cat"),"There is either a cat, or there is a dog, or both","there is neither a cat nor a dog")
Another broad option is to 'nest' one IF statement inside of another. ie:
=if(A1="dog","There is a dog. Have not checked for cats",if(B1="cat","A1 is not a dog, and also B1 is a cat","There is neither a cat nor a dog"))
If you have more specific questions you should update your question with all possible details you have.
It's a simple formula you could have found on google:
=ISNUMBER(FIND("dog",A1))
Will return True if dog is in A1 and false if it is not.
For further reading (well explained) https://exceljet.net/formula/cell-contains-specific-text
Also, it seems to me like this is a single-criteria. What do you mean by multiple criteria?
I have a parameter called Analyst group in this format :
[Dimension].[Analyst Group].&[Nl.Workplace.Foundation]
I want to pass this parameter to another report, to filter data. Its a multi value parameter. But the other report only accepts it in this format : [KanBan].[Analyst Group].&[Nl.Workplace.Foundation]
So im trying to isolate the "Nl.Workplace.Foundation", so i can do the following thing in the Go To Report parameter expression :="[KanBan].[Analyst Group].&["& --Isolated analyst group-- &"]" to create the desired format.
So what i need is to extract the part between .&[ and ]
But i really have no idea how to isolate that part of the string.
Found a solution! If i just use the Parameter.label instead of Parameter.value it automatically does what i want!
A different solution has been found, but I will still answer the initial question. It could help.
So what i need is to extract the part between .&[ and ]
You could use a regex.
This may not be the fastest way but it can handle most of the situations.
So let's assume you have a string containing:
[Dimension].[Analyst Group].&[Nl.Workplace.Foundation]
And you want to get the following string:
Nl.Workplace.Foundation
Just use the following expression:
=System.Text.RegularExpressions.Regex.Match("[Dimension].[Analyst Group].&[Nl.Workplace.Foundation]", "\.&\[(?<NWF>[^]]+)\]").Groups("NWF").Value
In the expression, replace the input string with your dynamic values, like for example:
=System.Text.RegularExpressions.Regex.Match(Fields!Dimension.Value & "." & Fields!AnalystGroup.Value, "\.&\[(?<NWF>[^]]+)\]").Groups("NWF").Value
I'm keeping the formula as simple as possible so that you can easily adapt it, with, say, handling the case where an input string will not have a match (with the above query it will return #Error).
You could do this by adding an IIF() or better, use a custom function that you can reuse in several places and will reduce the length of your expression.