Converting A If Formula In MS Excel To A MS Access Command/Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JudeFrancis
    New Member
    • Mar 2015
    • 1

    Converting A If Formula In MS Excel To A MS Access Command/Query

    Excel Formula:
    Code:
    =IF(U6<2,Z6*1,IF(U6<5,Z6*1.5,IF(U6<11,Z6*2,IF(U6<21,Z6*3,IF(U6<100000,Z6*5)))))
    
    =IF(V5<2,AA5*0.8,IF(V5<5,AA5*1,IF(V5<11,AA5*1.5,IF(V5<21,AA5*2,IF(V5<100000,AA5*3)))))
    
    =IF(W5<2,AB5*0.5,IF(W5<5,AB5*0.8,IF(W5<11,AB5*1,IF(W5<21,AB5*1.5,IF(W5<100000,AB5*2)))))
    
    =IF(X5<2,AC5*0.3,IF(X5<5,AC5*0.5,IF(X5<11,AC5*0.8,IF(X5<21,AC5*1,IF(X5<100000,AC5*1.5)))))
    
    =IF(Y5<2,AD5*1,IF(Y5<5,AD5*1,IF(Y5<11,AD5*1,IF(Y5<21,AD5*1,IF(Y5<100000,AD5*1)))))

    P.S- I tried converting these formulas as separate IIF functions in Access and it worked.

    But as I want it all together as a single field but it is showing up as "it is a too complex function for MS Access to process" .Please do help me out regarding this.
    Last edited by Rabbit; Mar 13 '15, 04:09 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Try the Switch() function. This behaves like a Select Case statement. In combination with the Between function, I think that it would be much easier to understand what is happening. The following example still uses the cell references, so those would need to be changed to the appropriate field or control references.
    Code:
    =Switch(U6 Between 0 and 1, Z6 * 1
    , U6 Between 2 And 4, Z6 * 1.5
    , U6 Between 5 And 10, Z6 * 2
    , U6 Between 11 And 20, Z6 * 3
    , U6 Between 21 And 100000, Z6 * 5)
    The other, more manageable approach would be to create a table that has three fields: LowRange, HighRange, Factor. This allows for you to easily change the ranges and the factors. Then you can just find the record that your values fits into and get that range.

    Comment

    Working...