Using Multiple criteria for iif Statemants

This criteria is based on the production number so far if it is >=73 or if it is <=4 it uses the first code but all else uses  the second code. The problem I have is that I have over 300 production number that need the first code. but in the 300 some do not so Im having to go aaround and pick and choose numbers.

How do I put like for example 300-400 as a criteria and then drop down to 200-250 with out having to name each production number individually? This is what Im tring to do.

IIf([Production]>=73 Or [Production]<=4 or [Production]=300-322 or [Production]= 400-422
and on with out having to name each number invidually instead of sayin 400 , 401, 402 etc.

This code works fine but i need to add more criteria

IIf([Production]>=73 Or [Production]<=4,

(Abs(([F]![Induction]*4+[F]![Defuel]*1+[F]![TurretPull]*3+[F]![FuelCellRemoved]*5+[F]![BFCSProvision]*3+[F]![Err]*10+[F]![TASS]*16+[F]![BASSDProvision]*8+[F]![BASSDInstalled]*14+[F]![BFCSInstalled]*10+[F]![TurretInstalled]*4+[F]![E1Ground]*1+[F]![DriverSeatSpacer]*1+[F]![GunnersSeatStop]*1+[F]![AFESSwitchGuard]*1+[F]![ReliefHoleExtinguisher]*1+[F]![25mmHotBox]*2+[F]![ErrHandleMod]*0+[F]![FuelShutoffSleeve]*1+[F]![FinalQAQC]*8+[F]![Outduction]*6)/100)*100),

(Abs(([F]![Induction]*5+[F]![Defuel]*1+[F]![TurretPull]*10+[F]![FuelCellRemoved]*10+[F]![BFCSProvision]*5+[F]![Err]*10+[F]![TASS]*10+[F]![BASSDProvision]*0+[F]![BASSDInstalled]*0+[F]![BFCSInstalled]*10+[F]![TurretInstalled]*10+[F]![E1Ground]*1+[F]![DriverSeatSpacer]*0+[F]![GunnersSeatStop]*1+[F]![AFESSwitchGuard]*1+[F]![ReliefHoleExtinguisher]*1+[F ]![25mmHotBox]*2+[F]![ErrHandleMod]*0+[F]![FuelShutoffSleeve]*1+[F]![FinalQAQC]*12+[F]![Outduction]*10)/100)*100)) & "%" AS Percentages
FROM tblYakimaFullup


Should I go another route?
gigifarrowAsked:
Who is Participating?
 
HooKooDooKuConnect With a Mentor Commented:
If you need a range of numbers in a if statement, then just use "AND"

iif([Production]<=4 OR ( [Production] >= 300 AND [Production] <= 322 ) OR ( [Production] >= 400 AND [Production] <= 422)...


Also note, the extra parenthesis are not required above.  The order of operations will cause AND to be executed before OR so the statement executes the same with or without the parenthesis.
0
 
armchair_scouseConnect With a Mentor Commented:
Gigi,

Looking at your criteria thus far:

[Production]>=73
[Production]<=4
[Production]=300-322
[Production]= 400-422

The last two criteria are already covered by the first criterion, because both 300-322 and 400-422 are greater than 73.

If you want to have specific production numbers that need to be included in your query, but the numbers are not sequential, e.g. 1,2,3,4,73,74,300,322, why not put the values in a 'SpecificProductionNumbers' table for example, and then update your query so that the table that has all of the other fields in your calculation (such as Induction, Defuel, etc.) links to the 'SpecificProductionNumbers' table by the Production field.  That way, you can add production numbers to the 'SpecificProductionNumbers' table and have them appear in your query which does all of the caculations.

It will also help simplify your IIF statement.
0
 
IrogSintaConnect With a Mentor Commented:
I agree with armchair_scouse about your criteria >=73.  That needs to be changed if you want to select other ranges above 73.

Another possibility is to create a function such as this:
Private Function GetType(iProduction As Integer) As Byte
    Select Case iProduction
        Case 300 To 322, 370, 379, 400 To 422, Is < 4
            GetType = 1
        Case Is > 500
            GetType = 2
        Case Else
            GetType = 3
    End Select
End Function

Open in new window

Then you can use the Choose function in your query:
Choose(GetType([Production]), Formula1 goes here, Formula2 goes here, Formula3 goes here)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.