Excel is throwing an error with my formula:
You have entered too many arguments for this function.
IF(AND(J2="Ounces",K2<=5),VLOOKUP(D2,'Parcel Select oz Lightweight'!$A$2:$B$17,2,0),IF(AND(J2="Ounces",K2>5),VLOOKUP(D2,'First Class oz'!$A$2:$B$17,2,0)),IF(AND(J2="Pounds",K2<=5),INDEX('lb and zones select'!$A$2:$K$73,MATCH(D2,'lb and zones select'!$A$2:$A$73,0),MATCH(H2,('lb and zones select'!$A$2:$K$2))),IF(AND(J2="Pounds",K2>5),INDEX('lbs and zones priority'!$A$2:$K$73,MATCH(D2,'lbs and zones priority'!$A$2:$A$73,0),MATCH(H2,'lbs and zones priority'!$A$2:$K$2,0)))))
I know its a really ugly formula.
As per your code, It looks like you just need to use parenthesis properly for each part to all if.
Normal If Block looks like this:
IF ( CONDITION,
<TRUE STATEMENT>,
<FALSE STATEMENT>
)
For nested statements or if, utilize parenthesis.
Put all nested true and false statement part in parenthesis:
IF ( CONDITION,
(<TRUE STATEMENT>),
(<FALSE STATEMENT>)
)
In this way your code can be look like this:
IF ( AND(J2="Ounces",K2<=5),
(VLOOKUP(D2,'Parcel Select oz Lightweight'!$A$2:$B$17,2,0)),
(IF(AND(J2="Ounces",K2>5),
(VLOOKUP(D2,'First Class oz'!$A$2:$B$17,2,0)),
(IF(AND(J2="Pounds",K2<=5),
(INDEX('lb and zones select'!$A$2:$K$73,MATCH(D2,'lb and zones select'!$A$2:$A$73,0),MATCH(H2,('lb and zones select'!$A$2:$K$2)))),
(IF(AND(J2="Pounds",K2>5),
(INDEX('lbs and zones priority'!$A$2:$K$73,MATCH(D2,'lbs and zones priority'!$A$2:$A$73,0),MATCH(H2,'lbs and zones priority'!$A$2:$K$2,0))),
(<Put a false part here, it was missing your code>)
))
))
))
)
Please check diff for above code and your code to get in detail about where you have missed the opening or closing of parenthesis.
If you break your code out with indentation, you'll see that your first IF has 4 arguments (Condition, True Statement, False Statement, Too Many Statements) and your second & fourth IFs only have 2 arguments:
=IF(
AND(J2="Ounces",K2<=5), //Condition
VLOOKUP(D2,'Parcel Select oz Lightweight'!$A$2:$B$17,2,0), //True
IF( //False
AND(J2="Ounces",K2>5), //Condition
VLOOKUP(D2,'First Class oz'!$A$2:$B$17,2,0) //True
), //No false?
IF( //Too many!
AND(J2="Pounds",K2<=5), //Condition
INDEX('lb and zones select'!$A$2:$K$73, //True
MATCH(D2,'lb and zones select'!$A$2:$A$73,0),
MATCH(H2,('lb and zones select'!$A$2:$K$2)) //Why the brackets?
),
IF( //False
AND(J2="Pounds",K2>5), //Condition
INDEX('lbs and zones priority'!$A$2:$K$73, //True
MATCH(D2,'lbs and zones priority'!$A$2:$A$73,0),
MATCH(H2,'lbs and zones priority'!$A$2:$K$2,0)
) //No false?
)
)
)
Looks like you have misplaced a bracket, and need to move it to the end.
(Skipping the False Statement statement will just mean that the formula returns FALSE in that situation)
Related
I have a multi-layered CASE statement, and one of the conditions needs to reference a table via a "not exists". I keep getting the error about 'correlated subqueries not allowed". How can I reference a table along with a condition inside a CASE statement? Below is a portion of my code:
WHEN ...... previous condition
WHEN ( CCOB_CLIENT_LOB_ID = 2 AND OI_CARRIER_LOB_ID IN (1,2,12,13) )
and not exists ( select S.STATE
FROM CCOB_PACIFICSOURCE.V_SELFPAY_COB_STATES S
WHERE S.STATE = SELFPAY_COB_STATE ) then 'NONE'
WHEN .... subsequent condition
The short answer is: you cann’t.
The longer answer is that you have to rewrite the query to outer join the table you give the alias S.
Then it’s quite possible to test for NULL.
Watch out for dublicates on the S.state column though :)
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)
I have a nested if statement is returning "False" rather than the expected outcome.
Scenario
Table "High VoltageCables" has data in it that default to numeric but may contain characters: kVa
Table "Master" checks "High VoltageCables" data as blank or not blank, and returns "Failed Check 1","Passed Check 1". This works fine.
Table "Meta" then checks the results of "Master" and then tests "High VoltageCables" data for length between 1 and 6, regardless of whether record is numeric or string.
Formula
=IF(MASTER!H2="Passed Check 1",IF(LEN('High VoltageCables'!O2)>=1,IF(LEN('High VoltageCables'!O2<6),"Passed Check 2","Failed Check 2")))
This is partially succesful, as it returns "Passed Check 2" for the following sample data in the source table "High VoltageCables".
1 numeric, or
1kVa str, or
50000 numeric
However if a field in "High VoltageCables"is blank, the formula returns "FALSE" rather than "Failed Check 1"
I inherited this task, (and would have preferred to do the whole thing in Access using relatively simple queries) - and unfortunately I am new to nested If statements, so I am probably missing something basic...
NB the data in High VoltageCables must default to numeric for a further check to work.
The first and second IF's seem to be missing the else part. They should be added at the end between the ))) like ), else ), else )
Every IF statement consists of IF( condition, truepart, falsepart) if you have two nested ifs it will be something like IF( condition, IF( condition2, truepart2, falsepart2), falsepart)
Hope that makes it a little clearer
You do have an unaccounted for FALSE in the middle IF. Try bring the latter two conditions together.
=IF(Master!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"))
It's still a bit unclear on what to show or not show if Master!H2 does not equal "Passed Check 1".
I failed to construct the formula with a concluding "else" - "Failed Check 1"
Using jeeped's and Tom's suggestion and adding the final "else" part I have solved the problem:
=IF(MASTER!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"),"Failed Check 1")
I understand that InterpolateRGBColors function is returning a color by position of value between 0 and 1... So its seems to be doable only with percentages, not numbers...
Is there a way to have the same functionality, but based on the min and max values returned in a set ?
What I want is to attribute colors to my measure but in a range of min([Measures].[NbSejours]) to max([Measures].[NbSejours]) ( not 0 to 1)...
WITH
MEMBER [Measures].[color] AS
InterpolateRGBColors(
[Measures].[NbSejours]
,rgb(176,224,230)
,rgb(135,206,235)
,rgb(0,191,255)
,rgb(100,149,237)
,rgb(0,0,255)
,rgb(0,0,139)
,rgb(25,25,112)
), BACK_COLOR=currentCellValue()
SELECT
{
{[Measures].[NbSejours]}
,[Measures].[color]
} ON COLUMNS
,{
NonEmpty
(
[Etablissement].[Etablissement].[Etablissement].ALLMEMBERS
,[Measures].[NbSejours]
)
} ON ROWS
FROM
(
SELECT
{{[Periode].[Periode].[All-M].&[2013]}} ON 0
FROM [Cube]
)
CELL PROPERTIES
STYLE
,CLASSNAME
,VALUE
,FORMATTED_VALUE;
Is there a way to do that ?
InterpolateRGBColors expect a numerical between 0 and 1 for interpolation. So we need to scale our measure to ensure we get the right colors.
There is an example in our live demo , here.
What we need is to scale [Measures].[NbSejours] between 0,1. There are two no documented function in icCube DistributionFlat & DistributionRank.
A non efficient version
WITH
SET [AxisX] AS NonEmpty([Etablissement].Etablissement].Etablissement].ALLMEMBERS,[Measures].[NbSejours])
FUNCTION distr(x_) as DistributionFlat( [AxisX], [Measures].[NbSejours], x_ )
MEMBER [Measures].[color] AS
InterpolateRGBColors(
distr([Measures].[NbSejours])
,rgb(176,224,230)
,rgb(135,206,235)
,rgb(0,191,255)
,rgb(100,149,237)
,rgb(0,0,255)
,rgb(0,0,139)
,rgb(25,25,112)
), BACK_COLOR=currentCellValue()
....
Once I got a bit of time I'll write a version using Vectors (here and here) that is more performant as in the example above we calculate every time the values for the set.
Hope it helps
I don'r know icCube so the following might not work, even though I have used standard functions. As #George commented you can use the standard RANK function to find each members relative position.
You will need to feed that value into the definition of [Measures].[color]...
WITH
SET [estMembersOrdered] AS
ORDER(
[Etablissement].[Etablissement].[Etablissement].ALLMEMBERS
,[Measures].[NbSejours]
,BDESC
)
MEMBER [Measures].[rnkEtablissement] AS
RANK(
[Etablissement].[Etablissement].CURRENTMEMBER
, [estMembersOrdered]
)
MEMBER [Measures].[color] AS
InterpolateRGBColors(
[Measures].[NbSejours]
,rgb(176,224,230)
,rgb(135,206,235)
,rgb(0,191,255)
,rgb(100,149,237)
,rgb(0,0,255)
,rgb(0,0,139)
,rgb(25,25,112)
), BACK_COLOR=currentCellValue()
SELECT
{
{[Measures].[NbSejours]}
,[Measures].[color]
,[Measures].[rnkEtablissement]
} ON COLUMNS
,{
NonEmpty
(
[Etablissement].[Etablissement].[Etablissement].ALLMEMBERS
,[Measures].[NbSejours]
)
} ON ROWS
FROM
(
SELECT
{{[Periode].[Periode].[All-M].&[2013]}} ON 0
FROM [Cube]
)
CELL PROPERTIES
STYLE
,CLASSNAME
,VALUE
,FORMATTED_VALUE;
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"))