IF function for specific text strings - excel

I am trying to write a formula that takes a word and process it through a IF function in excel, The Values are list in the formula. My issue right now is the fact that I have Large, X-Large and 1X-Large text. The X-Large and 1X-Large are unique strings and need the IF function to be able to differentiate the two.
Here is what i have so far.
=if(or(isnumber(search("Small",af2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),,ISNUMBER(SEARCH("X-Large",AF2))),"Small",or(isnumber(search("1X-Large",af2)),isnumber(search("2X-Large",af2)),isnumber(search("3X-Large",af2)),isnumber(search("4X-Large",af2))),"1X-Large")
I cant understand why it's showing an error and only displays small when it works.
All help is appreciated

Your current formula shouldn't work, it should be giving you an error about having too many arguments. A breakdown of your function:
=if(
or(isnumber(search("Small",af2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),,ISNUMBER(SEARCH("X-Large",AF2))),
"Small",
or(isnumber(search("1X-Large",af2)),isnumber(search("2X-Large",af2)),isnumber(search("3X-Large",af2)),isnumber(search("4X-Large",af2))),
"1X-Large"
)
You cannot use 4 parameters in an IF. You need to have a maximum of 3. Maybe what you meant was:
=if(
or(isnumber(search("Small",af2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),,ISNUMBER(SEARCH("X-Large",AF2))),
"Small",
IF(
or(isnumber(search("1X-Large",af2)),isnumber(search("2X-Large",af2)),isnumber(search("3X-Large",af2)),isnumber(search("4X-Large",af2))),
"1X-Large"
)
)
But that doesn't solve your issue about the X-Large part. To cater for that, you can check whether the X-Large series exist first, then the others.
=IF(
OR(ISNUMBER(SEARCH("1X-Large",AF2)),ISNUMBER(SEARCH("2X-Large",AF2)),ISNUMBER(SEARCH("3X-Large",AF2)),ISNUMBER(SEARCH("4X-Large",AF2))),
"1X-Large",
IF(
OR(ISNUMBER(SEARCH("Small",AF2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),ISNUMBER(SEARCH("X-Large",AF2))),
"Small"
)
)
Although you can make it shorter with this:
=IF(
OR(ISNUMBER(SEARCH({"1X-Large","2X-Large","3X-Large","4X-Large"},AF2))),
"1X-Large",
IF(
OR(ISNUMBER(SEARCH({"Small","Medium","Large","X-Large"},AF2))),
"Small"
)
)
In one line...
=IF(OR(ISNUMBER(SEARCH({"1X-Large","2X-Large","3X-Large","4X-Large"},AF2))),"1X-Large",IF(OR(ISNUMBER(SEARCH({"Small","Medium","Large","X-Large"},AF2))),"Small"))

Related

How to use Calculate with single condition on pivot?

In my pivot table I added a custom column like this:
=CALCULATE(MAX([Column1]),FILTER(table,expr))
I want to add a new condition and after a few tries, this is working as I expected
=IF([Column2]>5, CALCULATE(MAX([Column1]),FILTER(table,expr)) + 10,
CALCULATE(MAX([Column1]),FILTER(table,expr))
)
but this function is quite long (because expr pretty much the condition), I wonder if there is a LET function or some way that can shorten the above function
=CALCULATE( IF (
[Column2]>5,MAX([Column1])+10, MAX([Column1])
)
,FILTER(table,expr))
However this formula doesn't work,
Is there a better solution for this?

I keep getting "you've entered too many arguments for this function" Why"

I keep getting
You've entered too many arguments for this function
Why?
=IF(
Home!O17=6,
Home!H17,
0,
IF(
Home!O17=2,
Home!H20,
0,
IF(
Home!O17=3,
Home!H23,
0,
IF(
Home!O17=4,
Home!H26,
0,
IF(
Home!O17=5,
Home!H29,
0
)
)
)
)
Because you're passing four arguments into a three argument function. In Excel, the function call is:
=IF (logical_test, [value_if_true], [value_if_false])
Based on the structure, I am guessing you want to remove every "0," to get down to three args. Something like so:
=IF(Home!O17=6,Home!H17,IF(Home!O17=2,Home!H20,IF(Home!O17=3,Home!H23,IF(Home!O17=4,Home!H26,IF(Home!O17=5,Home!H29,0))))
That said, I have no idea what this should accomplish and I'm just guessing that you wanted to daisy chain this. Maybe it's actually supposed to be entirely separate statements.
Try this out.
=IF(Home!O17=6,Home!H17,IF(Home!O17=2,Home!H20,IF(Home!O17=3,Home!H23,IF(Home!O17=4,Home!H26,IF(Home!O17=5,Home!H29,0)))))

Error with formula trying to use IF(AND with three conditions

I am trying to write a formula to evaluate all possible values in three cells and score them in another. Excel says that there is a problem with my formula, but I can't locate it. Your help is appreciated.
I am using IF(AND throughout my spreadsheet, but only with two values. Those formulas are accepted by Excel.
=IF(AND(B2="No",B3="Red",B5="No"),0,
IF(AND(B2="No",B3="Green",B5="No",2,
IF(AND(B2="No",B3="Blue",B5="No",3,
IF(AND(B2="No",B3="Yellow",B5="No",5,5,
IF(AND(B2="No",B3="Red",B5="Yes"),0,
IF(AND(B2="No",B3="Green",B5="Yes"),2,
IF(AND(B2="No",B3="Blue",B5="Yes",3,
IF(AND(B2="No",B3="Yellow",B5="Yes",5,
IF(AND(B2="Yes",B3="Red",B5="Yes",0,
IF(AND(B2="Yes",B3="Green",B5="Yes",1,
IF(AND(B2="Yes",B3="Blue",B5="Yes",2,
IF(AND(B2="Yes",B3="Yellow",B5="Yes",5,
IF(AND(B2="Yes",B3="Red",B5="No",0,
IF(AND(B2="Yes",B3="Green",B5="No",1,
IF(AND(B2="Yes",B3="Blue",B5="No",2,
IF(AND(B2="Yes",B3="Yellow",B5="No",3))))))))))))))))
Excel states "There is a problem with this formula".
You had a 5,5 where you should have had a 5 and where missing many ) to close the ANDs
=IF(AND(B2="No",B3="Red",B5="No"),0,
IF(AND(B2="No",B3="Green",B5="No"),2,
IF(AND(B2="No",B3="Blue",B5="No"),3,
IF(AND(B2="No",B3="Yellow",B5="No"),5,
IF(AND(B2="No",B3="Red",B5="Yes"),0,
IF(AND(B2="No",B3="Green",B5="Yes"),2,
IF(AND(B2="No",B3="Blue",B5="Yes"),3,
IF(AND(B2="No",B3="Yellow",B5="Yes"),5,
IF(AND(B2="Yes",B3="Red",B5="Yes"),0,
IF(AND(B2="Yes",B3="Green",B5="Yes"),1,
IF(AND(B2="Yes",B3="Blue",B5="Yes"),2,
IF(AND(B2="Yes",B3="Yellow",B5="Yes"),5,
IF(AND(B2="Yes",B3="Red",B5="No"),0,
IF(AND(B2="Yes",B3="Green",B5="No"),1,
IF(AND(B2="Yes",B3="Blue",B5="No"),2,
IF(AND(B2="Yes",B3="Yellow",B5="No"),3,""))))))))))))))))
But I think you can do this with a simpler formula:
=IFERROR(IF(B2 = "No",CHOOSE(MATCH(B3,{"Red","Green","Blue","Yellow"},0),0,2,3,5),IF(B5="Yes",CHOOSE(MATCH(B3,{"Red","Green","Blue","Yellow"},0),0,1,2,5),CHOOSE(MATCH(B3,{"Red","Green","Blue","Yellow"},0),0,1,2,3))),"")
You could put your logic in string form in one cell (say, F1):
0NOREDNO 2NOGREENNO 3NOBLUENO 5NOYELLOWNO 0NOREDYES 2NOGREENYES 3NOBLUEYES 5NOYELLOWYES 0YESREDYES 1YESGREENYES 2YESBLUEYES 5YESYELLOWYES 0YESREDNO 1YESGREENNO 2YESBLUENO 3YESYELLOWNO
Then your code reduces to:
=MID(F1, FIND(UPPER(B2&B3&B5),F1)-1, 1)
This would also make it extremely easy to add more conditions in the future.
Try this:
=IF(B3="Red",0,
IF(B3="Green",
IF(B2="Yes",1,
IF(B2="No",2,NA())),
IF(B3="Blue",
IF(B2="Yes",2,
IF(B2="No",3,NA())),
IF(B3="Yellow",
IF(AND(B2="Yes",B5="No"),3,5),
NA()))))
Hope that helps

VBA If statments run fine on their own but not together too many arguments

These IF statements run fine on their own and work, but together they give me too many arguments error?
=IF(AND(AND(G11="M2M+",L11="Single"),OR(J11>1180,K11>2430)),Rules!G24,Rules!G23, IF(AND(AND(G11="M2M+",L11="Double"),OR(J11>1180,K11>2430)),Rules!G27,Rules!G28))
http://imgur.com/PlUbJ9k
Image here of price layout..
An if function has 3 arguments (the indentation is just for explanation purpose):
IF( Arguments in IF
Something is True, (1)
then do something, (2)
otherwise do something else (3)
)
If we indent your function the same way, you will clearly see that there are too many arguments (4) in the first if.
=IF( Argument in IF
AND( (1)
AND(G11="M2M+",L11="Single"),
OR(J11>1180,K11>2430)
),
Rules!G24, (2)
Rules!G23, (3)
IF( (4)
AND(
AND(G11="M2M+",L11="Double"),
OR(J11>1180,K11>2430)
),
Rules!G27,
Rules!G28
)
)
You need to end the first if after 3 Arguments with a closing bracket. It's hard to tell how the correct function would look like because we don't know what you are trying to achieve.
There is a possibility that you might be looking for this:
=IF(AND(G11="M2M+",OR(J11>1180,K11>2430)), IF(L11="Single",Rules!G24,IF(L11="Double", Rules!G27, Rules!G28)), Rules!G23)

Excel IF Function..too many arguments

I'm trying to figure out what I am doing wrong with this formula. It is returning the error "you've entered too many arguments for this function"
=IF(ROUND(d28=0,0,IF(b28<=$B$19,0,IF(AND($B$18="Fixed Balloon",b28=$B$20),d28,G28-f28))))
Thanks for the help
Try it like this, putting ROUND(d28,1)=0 instead of ROUND(d28=0...
=IF(ROUND(d28,1)=0,0,IF(b28<=$B$19,0,IF(AND($B$18="Fixed Balloon",b28=$B$20),d28,G28-f28)))
To make this clearer, showing what is happening, type it out in a text document in an indented format:
=IF(ROUND(d28,1)=0,
0,
IF(b28<=$B$19,
0,
IF(AND($B$18="Fixed Balloon",b28=$B$20),
d28,
G28-f28
)
)
)
Edit: ROUND takes 2 parameters, the first being the number to round, and the second being the number of digits to round to. I choose to make it round to one digit.
This could equally be written like this, which I find makes it easier to understand:
=IF(OR(ROUND(D28,1)=0,B28<=$B$19),
0,
IF(AND($B$18="Fixed Balloon",B28=$B$20),
D28,
G28-F28
)
)

Resources