+ Reply to Thread
Results 1 to 6 of 6

Making calculations upon multiple conditions without using many ugly IF's

  1. #1
    Forum Contributor
    Join Date
    03-05-2018
    Location
    Tbilisi, Georgia
    MS-Off Ver
    2013, 2016
    Posts
    271

    Making calculations upon multiple conditions without using many ugly IF's

    Good day, Experts.

    I need to make calculations depending on max / min values in A column.

    Values in A column are numbers of cartons.
    Data in Column B - list of juices with different volumes.
    In column G - I need to calculate correct pallete height depending on the below conditions:

    1. Cartons with 1L juices are 25 cm in height:
    For instance if quantity of 1L cartons on the pallete is less or equal 24 then pallete height = 3.
    The formula in this case is 0.25*3+0.15 (* - 0.15 is height of just pallete)

    2. if quantity of 1L cartons on the pallete is less or equal 30 then pallete height = 4.
    The formula: 0.25*4+0.15

    3. if quantity of 1L cartons on the pallete is less or equal 40 then pallete height = 5.
    The formula: 0.25*5+0.15

    Cartons with 330 ML juices are 20 cm in height:
    If quantity of 330 ML cartons on the pallete is less or equal 70 then pallete height = 7
    The formula: 0.2*7+0.15, If q-ty is less or equal 80, we just change 7 to 8

    Cartons with 330 ML and 1L cartons sometimes are mixed on the pallete. In this case quantities are indicated for each Carton. I couldn't solve this problem.

    Is there any way to get short formula without IF statements?
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-29-2020
    Location
    Indiana, USA
    MS-Off Ver
    M365
    Posts
    27

    Re: Making calculations upon multiple conditions without using many ugly IF's

    Greetings! I'm new here, but hope this helps! There is always more than 1 way to do complete this:

    Create a table on another sheet and do a lookup:
    =LOOKUP(A2,Sheet2!A:A,Sheet2!B:B)

    WIth a table of
    24 / 3
    30 / 4
    40 / 5
    70 / 7
    80 / 8

    This is easy for small amounts of data.

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Making calculations upon multiple conditions without using many ugly IF's

    I'm not sure I understand what you are trying to do, especially when mixed, but it ultimately looks like a pretty basic lookup with approximate match option. You want "largest value that is greater than or equal to lookup value" which means using the MATCH() function with the lookup data sorted in descending order.

    MATCH() help file: https://support.office.com/en-us/art...9-533f4a37673a
    INDEX() help file: https://support.office.com/en-us/art...2-b56b061328bd

    1) Enter your lookup and pallete height values in a lookup table:
    Please Login or Register  to view this content.
    2) Use MATCH() function to identify row# of the lookup value MATCH(A2,left_column_of_lookup_table,-1)
    3) Use INDEX() to return the pallete height INDEX(right_column_of_lookup_table,MATCH(...))
    4) Put that inside of your arithmetic expression G2 =0.25*INDEX(...)+0.15 and copy down.

    Does that help?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Contributor
    Join Date
    03-05-2018
    Location
    Tbilisi, Georgia
    MS-Off Ver
    2013, 2016
    Posts
    271

    Re: Making calculations upon multiple conditions without using many ugly IF's

    Hi Kirkules,

    Unfortunately my task is slightly more complex. I need to get the height of each pallet according to the height of each carton. Height of pallet is determined by rows.
    For example there are 3 rows with cartons containing 1L bottles.
    The height of each carton is 25 cm. Then 3 * 25 - 75 cm or 0.75 m. We need to add the height of pallet - 15 cm.
    And finally we get 0.90 meters height. (correct calculations are shown in my example)

    The problems is that cartons are of different height.
    Cartons with 330 ml bottles are 20 cm in height. And they can be mixed with 1L.
    I need to solve the double task: to shorten the cosmic length formula and also consider variable cartons on one pallete.

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Making calculations upon multiple conditions without using many ugly IF's

    Pleaes try

    =LOOKUP(A2,{24,30,40,70,80},{3,4,5,7,8})*(0.2+0.05*(A2<70))+0.15

  6. #6
    Forum Contributor
    Join Date
    03-05-2018
    Location
    Tbilisi, Georgia
    MS-Off Ver
    2013, 2016
    Posts
    271

    Re: Making calculations upon multiple conditions without using many ugly IF's

    Hi, Bo_Ry,

    Amazing! This is exactly the algorithm that I was looking for! Thank you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Decision making based on multiple conditions
    By MyVBA in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2019, 06:33 AM
  2. Making calculations, depending on other cells
    By Tuxx in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-25-2015, 07:40 AM
  3. [SOLVED] Excel 2007 : Making time zone calculations in Excel
    By fabes253 in forum Excel General
    Replies: 2
    Last Post: 07-04-2012, 05:24 PM
  4. Help making some calculations
    By stsams in forum Excel General
    Replies: 2
    Last Post: 01-30-2012, 07:08 PM
  5. Working with Dates and making calculations
    By cultavix in forum Excel General
    Replies: 14
    Last Post: 01-08-2009, 07:01 AM
  6. Making calculations using data from other sheets?
    By endlyss in forum Excel General
    Replies: 4
    Last Post: 06-27-2008, 04:00 PM

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