+ Reply to Thread
Results 1 to 15 of 15

if Statement with Multiple Conditions Help Please

  1. #1
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    if Statement with Multiple Conditions Help Please

    Hello

    I have three variables with total possibilties of 5 x9x3 = 135

    is there effiscient way wrtting a code that would depending on value of X, Y, Z

    I know if Statement can only owrk with Boolean Variable and gets complicated setting precedence given the multpile possibilities

    Thank you


    X Y Z Conditions

    X1 Y1 Z1 Values
    X2 Y2 Z2
    X3 Y3 Z3
    X4 Y4
    X5 Y5
    Y6
    Y7
    Y8
    Y9

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: if Statement with Multiple Conditions Help Please

    Select Case or a multi-dimensional array may be appropriate, but without understanding exactly what you're trying to do with each variable combination, it's hard to advise specifically...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: if Statement with Multiple Conditions Help Please

    You could set up a table of the combinations and possible outcomes and then use VLOOKUP to match the concatenated values to the Table


    A
    B
    C
    D
    E
    F
    G
    H
    1
    X
    Y
    Z
    XYZ
    Outcome
    2
    X1
    Y1
    Z1
    X1Y1Z1
    Outcome 1
    x1
    3
    X1
    Y1
    Z2
    X1Y1Z2
    Outcome 2
    y2
    4
    X1
    Y1
    Z3
    X1Y1Z3
    Outcome 3
    z3
    5
    X1
    Y2
    Z1
    X1Y2Z1
    Outcome 4
    6
    X1
    Y2
    Z2
    X1Y2Z2
    Outcome 5
    x1y2z3
    =G2&G3&G4
    7
    X1
    Y2
    Z3
    X1Y2Z3
    Outcome 6
    Outcome 6
    =VLOOKUP(G2&G3&G4,D:E,2,FALSE)
    8
    X1
    Y3
    Z1
    X1Y3Z1
    Outcome 7
    Outcome 6
    =VLOOKUP(G6,D:E,2,FALSE)
    9
    X1
    Y3
    Z2
    X1Y3Z2
    Outcome 8
    10
    X1
    Y3
    Z3
    X1Y3Z3
    Outcome 9
    11
    X1
    Y4
    Z1
    X1Y4Z1
    Outcome 10
    12
    X1
    Y4
    Z2
    X1Y4Z2
    Outcome 11
    13
    X1
    Y4
    Z3
    X1Y4Z3
    Outcome 12
    14
    X1
    Y5
    Z1
    X1Y5Z1
    Outcome 13
    15
    X1
    Y5
    Z2
    X1Y5Z2
    Outcome 14
    16
    X1
    Y5
    Z3
    X1Y5Z3
    Outcome 15


    etc ...


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: if Statement with Multiple Conditions Help Please

    Quote Originally Posted by Olly View Post
    Select Case or a multi-dimensional array may be appropriate, but without understanding exactly what you're trying to do with each variable combination, it's hard to advise specifically...
    Hope this diagramm of the logic help explain what I am trying to achieve


    Thank you
    Please Login or Register  to view this content.
    Last edited by bimo; 12-01-2014 at 06:50 AM.

  5. #5
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: if Statement with Multiple Conditions Help Please

    Quote Originally Posted by TMS View Post
    You could set up a table of the combinations and possible outcomes and then use VLOOKUP to match the concatenated values to the Table


    A
    B
    C
    D
    E
    F
    G
    H
    1
    X
    Y
    Z
    XYZ
    Outcome
    2
    X1
    Y1
    Z1
    X1Y1Z1
    Outcome 1
    x1
    3
    X1
    Y1
    Z2
    X1Y1Z2
    Outcome 2
    y2
    4
    X1
    Y1
    Z3
    X1Y1Z3
    Outcome 3
    z3
    5
    X1
    Y2
    Z1
    X1Y2Z1
    Outcome 4
    6
    X1
    Y2
    Z2
    X1Y2Z2
    Outcome 5
    x1y2z3
    =G2&G3&G4
    7
    X1
    Y2
    Z3
    X1Y2Z3
    Outcome 6
    Outcome 6
    =VLOOKUP(G2&G3&G4,D:E,2,FALSE)
    8
    X1
    Y3
    Z1
    X1Y3Z1
    Outcome 7
    Outcome 6
    =VLOOKUP(G6,D:E,2,FALSE)
    9
    X1
    Y3
    Z2
    X1Y3Z2
    Outcome 8
    10
    X1
    Y3
    Z3
    X1Y3Z3
    Outcome 9
    11
    X1
    Y4
    Z1
    X1Y4Z1
    Outcome 10
    12
    X1
    Y4
    Z2
    X1Y4Z2
    Outcome 11
    13
    X1
    Y4
    Z3
    X1Y4Z3
    Outcome 12
    14
    X1
    Y5
    Z1
    X1Y5Z1
    Outcome 13
    15
    X1
    Y5
    Z2
    X1Y5Z2
    Outcome 14
    16
    X1
    Y5
    Z3
    X1Y5Z3
    Outcome 15


    etc ...


    Regards, TMS
    Thanks that is going to get me closer to a solution, I made a Table with 130 Possibilities and about 40 outcome is that mean 40 If statement and Esle ? Thanks

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: if Statement with Multiple Conditions Help Please

    Here's another approach:

    Please Login or Register  to view this content.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: if Statement with Multiple Conditions Help Please

    No, you need a table with all 135 options. Some of the outcomes will be duplicated/replicated/whatever. You would build a key from the X, Y and Z values and then use that key to look in column D and return the outcome from column E.

    Regards, TMS

  8. #8
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: if Statement with Multiple Conditions Help Please

    Quote Originally Posted by Olly View Post
    Here's another approach:

    Please Login or Register  to view this content.

    Looks the work of Genius, thank you so much!! ..I am struggling tough with the final touches, i.e setting the criteria ..see my comments, I have done the donkey work for you and filled the input/output data.

    Await your comments so I can make it for me.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: if Statement with Multiple Conditions Help Please

    Okay, your criteria / output mapping is different now to your initial example, so we can take the loops out. Function now looks like:

    Please Login or Register  to view this content.

    Now, if your MyX, MyY and MyZ variables are in columns E, F and G respectively, then you could write the formula using:

    Please Login or Register  to view this content.
    Now, looking at this comment:
    'that is the result I get =VLOOKUP(XFC2, Sheet2!P:XFC, lookatcol(MyX,MyY,MyZ), FALSE), guess because I have not set my criteria
    I'm guessing you don't really want to be referencing column XFC, so it looks like your relative column references aren't quite what you wanted....

    It's quite hard to provide a specific solution without a specific example outcome to work towards!

  10. #10
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: if Statement with Multiple Conditions Help Please

    It's quite hard to provide a specific solution without a specific example outcome to work towards!

    here is the example with input and out put, makes it easier to nail this,

    Thank you!

    PS : on sheet Outcome, there will be many rows, so the formula need to loop, as far Column A last`s row.
    Attached Files Attached Files
    Last edited by bimo; 12-01-2014 at 11:29 AM.

  11. #11
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: if Statement with Multiple Conditions Help Please

    So why not just use:
    Formula: copy to clipboard
    Please Login or Register  to view this content.



  12. #12
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: if Statement with Multiple Conditions Help Please

    Quote Originally Posted by Olly View Post
    So why not just use:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    WOW one powerfull formulae !! ,,will I be able to add more variables to it ?

  13. #13
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: if Statement with Multiple Conditions Help Please

    Quote Originally Posted by bimo View Post
    WOW one powerfull formulae !! ,,will I be able to add more variables to it ?
    Yes, you can add further criteria to the SUMIFS formula.

  14. #14
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: if Statement with Multiple Conditions Help Please

    Quote Originally Posted by Olly View Post
    Yes, you can add further criteria to the SUMIFS formula.
    Excellent!!, that would definitely help, if it is not too much hassle for you, would still love to get your code working, I might be able to customize it into a flexible model that suits my expanding needs , much appreciated!!

  15. #15
    Forum Contributor
    Join Date
    01-03-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: if Statement with Multiple Conditions Help Please

    Quote Originally Posted by Olly View Post
    Yes, you can add further criteria to the SUMIFS formula.
    on 50K upwards row File, it is really slow..

+ 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. IF Statement - multiple conditions - HELP!
    By rcocalm in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-02-2013, 01:57 PM
  2. IF statement with multiple conditions
    By nicko54 in forum Excel General
    Replies: 5
    Last Post: 01-22-2009, 09:18 AM
  3. IF statement w/multiple conditions
    By JimS in forum Excel General
    Replies: 1
    Last Post: 04-14-2008, 09:32 AM
  4. IF Statement with multiple conditions
    By Ladypep in forum Excel General
    Replies: 3
    Last Post: 04-05-2006, 09:50 AM
  5. [SOLVED] If statement using multiple conditions
    By SCOOBYDOO in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-06-2005, 02:05 AM

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