+ Reply to Thread
Results 1 to 11 of 11

Nested IF/AND statements

  1. #1
    Registered User
    Join Date
    11-11-2012
    Location
    Alice Springs
    MS-Off Ver
    Excel 2002
    Posts
    5

    Nested IF/AND statements

    Hi, I'm having a little trouble with the logic in writing a nested IF/AND statement.

    I want to make a calculator to determine the cost of mileage at the following rates

    Distance Boundaries Rate/km
    0 100 $2.00
    101 500 $1.75
    501 2000 $1.50
    2001 6000 $1.25
    6001 infinity $1.00

    That is, if I travel 1500 miles, the first 100 will be at $2, the next 400 will be at $1.75, etc

    0 - 100 is easy, but the next lines have me puzzled

    the best I have come up with for 101 to 500 so far is

    =IF(AND(E$12>=$B16,E12<=$C16),$D16*(E$12-C15))

    Is it OK to attach the file?

    Cheers
    Roy Price
    Alice Springs
    Australia
    Attached Files Attached Files
    Last edited by Roy Price; 11-11-2012 at 04:10 AM.

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Nested IF/AND statements

    Try this consolidated formula..

    =SUMPRODUCT(--(E12>{0,100,500,2000,6000,100000}), E12-{0,100,500,2000,6000,100000}, {2,-0.25,-0.25,-0.25,-0.25,-0.25})
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Nested IF/AND statements

    are the kilometre values constant, or are they changeable?, or at least, stored in that way in actual table?...there are several answers, but I need more info, maybe someone else can do of the cuff, but I need more info
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  4. #4
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Nested IF/AND statements

    aah, there you go, someone better qualified !
    I'll let Ace take from here

  5. #5
    Registered User
    Join Date
    11-11-2012
    Location
    Alice Springs
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Nested IF/AND statements

    Quote Originally Posted by Ace_XL View Post
    Try this consolidated formula..

    =SUMPRODUCT(--(E12>{0,100,500,2000,6000,100000}), E12-{0,100,500,2000,6000,100000}, {2,-0.25,-0.25,-0.25,-0.25,-0.25})
    Thanks, I haven't seen this solution before, have no idea how it works, but can see what I need to change if alter my parameters in the future

    Great job. Thank you

  6. #6
    Registered User
    Join Date
    11-11-2012
    Location
    Alice Springs
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Nested IF/AND statements

    Thanks for responding. Anoher post has provided a great soluton to my proble.
    To answer your question the km values might change as might the cost per kms
    However, I will be able to use what Ace_XL sent me

    Thanks again

  7. #7
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Nested IF/AND statements

    could you post the thread that you got the answer fr m?
    would probably help other members of the site...

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Nested IF/AND statements

    Hi Roy,

    If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit. Also, please mark the thread as Solved.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  9. #9
    Registered User
    Join Date
    11-11-2012
    Location
    Alice Springs
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Nested IF/AND statements

    Hi Ace_XL

    Thanks for your help. I made some alterations to the kilometer ranges and altered the SUMPRODUCT statement to what I thought should work

    The distance ranges are as follows (with calculations)

    Distance to be calculated 4836kms

    distance ranges cost/kg
    first 500kms $2.00 500 $1,000
    next 1000kms $1.75 1000 $1,750
    next 2000kms $1.50 2000 $3,000
    next 4000kms $1.25 1336 $1,670
    remaining kms $1.00 0 $-

    TOTAL KMS 4836 $7,420

    I altered the SUMPRODUCT statement to match the changes:

    =SUMPRODUCT(--(E3>{0,500,1000,2000,4000,100000}),E3-{0,500,1000,2000,4000,100000}, {2,-0.25,-0.25,-0.25,-0.25,-0.25})

    But this returns a different result ($6711) from what I get from the method above ($7420).

    Am I missing something? What am I doing wrong?

    Cheers
    Roy Price
    Alice Springs

  10. #10
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Nested IF/AND statements

    The ranges should be cumulative. Hence use

    =SUMPRODUCT(--(E2>{0,500,1500,3500,7500,100000}),E2-{0,500,1500,3500,7500,100000}, {2,-0.25,-0.25,-0.25,-0.25,-0.25})

  11. #11
    Registered User
    Join Date
    11-11-2012
    Location
    Alice Springs
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Nested IF/AND statements

    Quote Originally Posted by Ace_XL View Post
    The ranges should be cumulative. Hence use

    =SUMPRODUCT(--(E2>{0,500,1500,3500,7500,100000}),E2-{0,500,1500,3500,7500,100000}, {2,-0.25,-0.25,-0.25,-0.25,-0.25})
    Fantastic. Thanks again.

    Cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1