Using the IF function with a range of numbers

I am working with the IF function and trying to get it to work "if" the number I'm examining is within a range of numbers.


Example:


If a wigit costs between $1000 and $1999, then a discount of $100 is given

If a wigit costs between $2000 and $2999, then a discount of $150 is given

If a wigit costs between $3000 and $3999, then a discount of $225 is given


And so on.


If cell A1 always holds the current cost of the wigit being sold.

cell B1,B2,B3 holds the value of the discount values respectively.


In cell C1 I would like to return what the current discount value is to be given for the wigit price in cell A1?


How do I do this using the IF function or is there another way?


Thanks,

Ryan

Posted on Aug 30, 2012 12:51 PM

Reply
14 replies

Aug 30, 2012 1:23 PM in response to RyanScheib

I suggest using a different method which involves adding a second table that contains the threshold/discount pairs. This makes it easier to adjust later:


User uploaded file


I added the table "Discount" (on the right). The first row is a header in BOTH tables.


The table on the left is set up as follows:

C2=IFERROR(VLOOKUP(B2,Discount :: A:B, 2, 1), 0)


select C2 and fill down as needed

Aug 30, 2012 2:29 PM in response to RyanScheib

Ryan,


I did not present anything with regard to computing the cost. If the you have several items that change cost regularly you could add yet another table for the cost of items:


User uploaded file


I called the new table "Global Information". Then I inserted two new columns (one for "Item" and one for "QTY")

D2=IFERROR(VLOOKUP(B2,Global Information :: A:B, 2, 0), 0)*C2

E2=IFERROR(VLOOKUP(D2,Discount :: A:B, 2, 1), 0)


select D2 and E2 and fill down

Aug 31, 2012 7:47 AM in response to RyanScheib

Ryan,


Here is another variation of what I previously presented with your specific ranges. Please note this can be done without a lookup table but the translation from amount spent to gift card amount is NOT linear. I can determine an approximation for the function that would perform this translation but my opinion is the lookup is more straight forward:


User uploaded file


The example takes input from the "Line Cost" column and looks up that value int he "Gift Card" table and returns the value from the 2nd column in the row that is less than the "Line Cost".


I hope this helps

Aug 31, 2012 11:56 AM in response to Jerrold Green1

I think part of my problem is I'm pretty much novice here and that answer about boggled my mind. I'm using the ipad to do the entire project. Here is what I had in mind, tell me if you can make this work.


The below example would work this way. Each line would individually check the purchase price to find out if it fell into that range. If not the line reports back a FALSE or 0 response. If the purchase price does fall into the range of that line then it returns a TRUE and displays the $ amount of the Cash Card. I simply then at all the lines up where the 0 and Cash Card amount is displayed and show that number on the screen shot I displayed before.


User uploaded file

Sep 6, 2012 2:38 AM in response to RyanScheib

HI Ryan,


In this post you have, except for the issue noted by Badunit, the basis for the discount table described by Wayne:


I'm trying to devise a way of knowing what Cash Card a customer will receive depending on the amount of the purchase, based on the following table:


$0 to $999 purchase = $50 Cash Card

$1,000 to $1,999 purchase = $100 Cash Card

$2,000 to $2,999 purchase = $200 Cash Card

$3,000 to $3,999 purchase = $300 Cash Card

$4,000 to $4,999 purchase = $400 Cash Card

$5,000 to $5,999 purchase = $550 Cash Card

$6,000 to $6,999 purchase = $700 Cash Card

$7,000 to $7,999 purchase = $850 Cash Card

$8,000 to $8,999 purchase = $1,000 Cash Card

$9,000 to $9,999 purchase = $1,200 Cash Card

$10,000 to UP purchase = $1,500 Cash Card


To take care of the issue noted by Badunit, you need to revise the top line to state the minimum purchase necessary to earn a cash card, then add a line above that to handle purchases under that amount. I've arbitrarily chosen a $500 minimum, which results in these two lines:


$0 to $499 purchase = $0 Cash Card

$500 to $999 purchase = $50 Cash Card


To write this as Wayne's table, you need to remove all of the text (including the $ currency markers), the top end of each range, and the = sign. What you're left with is two columns of numbers: The bottom number of each range of values, and the number telling the dollar amount of the cash card for that range. Here's your table, edited to make it work with LOOKUP:

User uploaded file


Here is a second table (Main), containing only the labels and the two cells involved in the calculation of the cash card amount. The Purchase amount is the amount used in your example. The Cash Card amount is produced by the LOOKUP formula below the image.

User uploaded file

Purchase price is in cell B1 of the table "Main". The LOOKUP formula is in B2:


B2: =LOOKUP(B1,CC Amt :: A,CC Amt :: B)


LOOKUP acts essentially as you request in your post containing the iPad image with the time shown as 1:46. But it takes a much simpler approach.


Here's the syntax:


LOOKUP(search-for,search-where,return-from)


LOOKUP gets the search-for value (2535) from cell B1.

It looks in column A of the table "CC Amt" for the largest value less than or equal to the search-for value, and finds 2000.

It returns the value from the same line of column B (200).


Below are two more examples. Main-2 and Main-3 are copies of the Main table. Both contain exactly the same formula as Main, but have had a different Purchase price amount entered. LOOKUP uses the same CC Amt table as is used above, and returns the appropriate Cash Card value for each of the two new amounts:

User uploaded file

You may, as implied in your 1:46 post, use a pair of cells to calculate the Cash Card amount for each widget in the purchase, then total the Cash Card amounts, or you may use a single pair of cells, one containing the total purchase amount, the other containing the Cash Card amount due for that total. That choice is yours. The formula is the same for either case.


Regards,

Barry

Aug 30, 2012 6:25 PM in response to RyanScheib

Another solution that assumes the pattern you gave continues:


$0-999 = $0

$1000-1999 = $100

$2000-2999 = $150 ($50 more than the previous category)

$3000-3999 = $225 ($75 more than the previous category)

$4000-4999 = $325 ($100 more than the previous category)

etc


Discount =IF(B<1000,0,12.5*(INT(B/1000))^2+12.5*INT(B/1000)+75) where the value is in B


Of course, at around $40,000 it becomes a 50% discount and at $79,000 and above the discount will exceed the price.


If you provide more info on the discount, maybe a better formula can be constructed. Or maybe you should reconsider the steepness of the discount curve or apply a simple percentage instead.

Aug 31, 2012 7:34 AM in response to Badunit

Here is the actual entire group I'm working with, as you will see I'm trying to devise a way of knowing what Cash Card a customer will recieve depending on the amount of the purchase, based on the following table:


$0 to $999 purchase = $50 Cash Card

$1,000 to $1,999 purchase = $100 Cash Card

$2,000 to $2,999 purchase = $200 Cash Card

$3,000 to $3,999 purchase = $300 Cash Card

$4,000 to $4,999 purchase = $400 Cash Card

$5,000 to $5,999 purchase = $550 Cash Card

$6,000 to $6,999 purchase = $700 Cash Card

$7,000 to $7,999 purchase = $850 Cash Card

$8,000 to $8,999 purchase = $1,000 Cash Card

$9,000 to $9,999 purchase = $1,200 Cash Card

$10,000 to UP purchase = $1,500 Cash Card

Sep 4, 2012 6:41 AM in response to RyanScheib

Using an entire table to do the same thing as what can be done in a simple single-cell formula (such as Jerry provided) seems inefficient. You would be better served by de-boggling your mind and trying to understand the formula versus using a very inefficient approach.


You might want to reconsider your first tier for the gift card/cash card. You have it as $0-$999 = $50 card. As an astute customer, I'd buy a bunch of $1 items one at a time and receive $50 gift cards for each purchase. Quite a deal!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using the IF function with a range of numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.