+ Reply to Thread
Results 1 to 6 of 6

Restructure a if statement

  1. #1
    Registered User
    Join Date
    07-03-2008
    Location
    Johannesburg
    Posts
    15

    Restructure a if statement

    Hello

    I have a rates tariff which I would like to automate,

    The tariff structure is

    First half kilo : Per half kilo up to 5 : +5 kilos : +20 kilos : + 30 kilos

    I am trying to do so by using something like this:-

    =IF(O13<0.5,D13,IF(O13>0.5<5,13*F13*2+D13-F13,IF(O13>5<20,O13*L13,IF(O13>20<30,O13*M13,IF(O13>30,O13*N13)))))

    Which does not work.

    Basically I want the user to enter a weight into O13 and then have the rate calculated as follows

    1. if the weight in O13 is less than 0.5 the rate in D13 applies
    2. If the weight is greater than 0.5 the rate is the first half kilo (D13) + the rate for every half kilo up to 5 kilos (if somebody shipped 3 kilos the rate would be D13 -first half) + 2.5 kilos * F13 * 2)
    3. if the weigh is >5 kilos but <20 kilos the flat rate is O13*L13
    4. If the weight is >20 kilos but <30 kilos the flat rate is O13*M13
    5. if the weight is >30 kilos the flat rate is 013*N13

    Could somebody help me to restructure my formula so that it works

    Thank you very much

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Try

    =IF(O13="","",CHOOSE(MATCH(O13,{0,0.5,5,20,30}),D13,D13+F13*CEILING(O13*2-1,1),O13*L13,O13*M13,O13*N13))

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Try:

    =IF(O13<0.5,D13,IF(O13<5,13*F13*2+D13-F13,IF(O13<20,O13*L13,IF(O13<30,O13*M13,O13*N13))))


    Since the conditions are checked sequentially in the IF statement as soon as one item becomes True, the True result is applied.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Registered User
    Join Date
    07-03-2008
    Location
    Johannesburg
    Posts
    15

    Problem resolved

    Thanks to you both

    Sorry for the late response but my laptop decided to blow up!!

    I have taken Daddy Longleg's advice as it returns the correct answer whereas the other does not (probably my implementation not the advice)

    A couple of questions please, sorry to be a pain but I prefer to learn and understand what I am doing rather than copying and pasting

    "." followed by Choose: does this mean any number input into O13 is Matched to the numbers shown between {}

    {} I have not seen these types of brackets in a formula before what do they actually do?

    Thanks a lot

    Danny

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    The attached figure may help, Danny.
    Attached Images Attached Images
    Last edited by shg; 07-04-2008 at 12:45 PM.

  6. #6
    Registered User
    Join Date
    07-03-2008
    Location
    Johannesburg
    Posts
    15

    Restructured formula

    Good morning

    Daddy Longlegs kindly gave me a solution to a tariff problem that I encountered

    =IF(O13="","",CHOOSE(MATCH(O13,{0,0.5,5,20,30}),D13,D13+F13*CEILING(O13*2-1,1),O13*L13,O13*M13,O13*N13))

    In another tariff I have a slightly different structure which is

    B10 = First kilo charge (this is always charged + any additional Kilos)
    C10 = Rate per kilo for less than 10 kilos
    E10 = +10 kilos
    F10 = +20 kilos
    G10 = + 30 kilos
    H10 = + 45 kilos

    If then for example I had 25 kilos the result would be B10+24*F10, in my normal crude way I have tried to express this in a formula (that needless to say does not work) to show you what I mean

    =IF(J10<10,B10+C10*J10-C10,IF(J10>10<19,B10+E10*J10-E10,IF(J10>20<30,B10+F10*J10-F10,IF(J10>30<45,B10+G10*J10-G10,IF(J10>45,B10+H10*J10-H10)))))

    I tried to adapt the Daddy Longlegs formula to reflect this

    IF(J10="","",CHOOSE(MATCH(J10,{0,1,10,20,30,45} but I got this far and everyhting else I tried just did not help

    Any suggestions gratefully received

    Danny

+ 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