+ Reply to Thread
Results 1 to 6 of 6

Using AND to check 2 conditions...

Hybrid View

  1. #1
    Registered User
    Join Date
    12-31-2008
    Location
    Alaska, (not Anchorage)
    MS-Off Ver
    Excel 2010, 2016, and 365
    Posts
    78

    Using AND to check 2 conditions...

    Hello all-
    I'm trying to work an AND statement in to a formula so that if 2 conditions are met (fuel and type) then the date of that record will be displayed along with the other matched dates in ascending order on a report tab. This statement works for a single condition,

    =INDEX(data!$A$1:$A$100,SMALL(IF(data!$B$1:$B$100=$A$3,ROW(data!$A$1:$A$100)),ROWS($B$2:B3)))

    and this is the statement that I've been trying to get to work for two conditions,

    =INDEX(data!$A$1:$A$100,SMALL(IF(AND(data!$C$1:$C$100=$B$3,data!$B$1:$B$100=$A$3),ROW(data!$A$1:$A$100)),ROWS($B$2:B3)))


    Where am I dropping the ball here? I've also attached a workbook with this example in it.

    Thanks in advance for wisdom and insight shared.




    <data tab>

    date | type | fuel
    6/21/2011 | Blue Volvo | diesel
    6/21/2011 | Red Citroen | electric
    6/23/2011 | White Landcruiser | gasoline
    6/23/2011 | Green Ford | diesel
    6/23/2011 | Silver Toyota | electric
    6/23/2011 | White Landcruiser | diesel
    6/28/2011 | Blue Volvo | corn oil
    6/28/2011 | Red Citroen | electric
    6/28/2011 | Yellow Mazda | gasoline
    6/28/2011 | Green Ford | diesel
    7/2/2011 | White Landcruiser | electric
    7/2/2011 | Silver Toyota | electric
    7/2/2011 | Green Ford | diesel
    7/2/2011 | Yellow Mazda | corn oil
    7/3/2011 | White Landcruiser | diesel
    7/3/2011 | Blue Volvo | gasoline
    7/12/2011 | White Landcruiser | electric

    <report tab>

    White Landcruiser | electric
    7/2/2011
    7/12/2011

    White Landcruiser | diesel
    6/23/2011
    7/3/2011

    Red Citroen | electric
    6/21/2011
    6/28/2011
    Attached Files Attached Files

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using AND to check 2 conditions...

    I'm running out of the door so have not looked at your file but in terms of Array / SUMPRODUCT functions - in general terms:

    You can not use AND/OR functions
    ANDs are performed by means of *
    ORs are performed by means of +

    In your example - an AND based test would look like:

    =INDEX(...,SMALL(IF((test1)*(test2),ROW(...)),ROWS(...)))
    alternatively - you can use embedded IFs

    =INDEX(...,SMALL(IF(test1,IF(test2,ROW(...))),ROWS(...)))
    the latter is arguably more efficient but pending version you are limited regards number of embedded IFs you may use.

    Quickly glancing at your data set ... if returning numbers (ordered etc...) you don't really need the INDEX as you can use a single SMALL - ie use the Date field rather than Row and apply k to the dates.

    Also... Pivot Table(s) ?

  3. #3
    Registered User
    Join Date
    12-31-2008
    Location
    Alaska, (not Anchorage)
    MS-Off Ver
    Excel 2010, 2016, and 365
    Posts
    78

    Re: Using AND to check 2 conditions...

    Got it-

    The below worked great to parse out the dates
    ={INDEX(data!$A$1:$A$100,SMALL(IF((data!$E$1:$E$100=$B$2)*(data!$C$1:$C$100=$A$2),ROW(data!$A$1:$A$100)),ROWS($B$1:B1)))}

    I'm working on copying the count value for each specific incidence of date-type-fuel.

    Here is what I have so far working with nested IF statements:
    =INDEX(data!$A$1:$A$100,IF(data!$E$1:$E$100=$B$2,IF(data!$C$1:$C$100=$A$2,IF(data!$A$1:$A$100=$C2),ROW(data!$D$1:$D$100)))),ROWS($B$1:B1))))
    This would go in D2 on the report tab.

    Help. File uploaded.
    Thanks in advance.


    <data tab>

    date | type | fuel | count
    6/21/2011 | Blue Volvo | diesel | 13
    6/21/2011 | Red Citroen | electric | 12
    6/23/2011 | White Landcruiser | gasoline | 11
    6/23/2011 | Green Ford | diesel | 12
    6/23/2011 | Silver Toyota | electric | 15
    6/23/2011 | White Landcruiser | diesel | 12
    6/28/2011 | Blue Volvo | corn oil | 17
    6/28/2011 | Red Citroen | electric | 19
    6/28/2011 | Yellow Mazda | gasoline | 12
    6/28/2011 | Green Ford | diesel | 10
    7/2/2011 | White Landcruiser | electric | 11
    7/2/2011 | Silver Toyota | electric | 12
    7/2/2011 | Green Ford | diesel | 15
    7/2/2011 | Yellow Mazda | corn oil | 12
    7/3/2011 | White Landcruiser | diesel | 23
    7/3/2011 | Blue Volvo | gasoline | 12
    7/12/2011 | White Landcruiser | electric | 13

    <report tab>
    type | fuel | date | count
    White Landcruiser | electric | 7/2/2011 | 11
    | | 7/12/2011 | 13

    White Landcruiser | diesel | 6/23/2011 | 12
    | | 7/3/2011 | 23

    Red Citroen | electric | 6/21/2011 | 12
    | | 6/28/2011 | 19
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-31-2008
    Location
    Alaska, (not Anchorage)
    MS-Off Ver
    Excel 2010, 2016, and 365
    Posts
    78

    Re: Using AND to check 2 conditions...

    This,

    =INDEX(data!$F$1:$F$100,SMALL(IF((data!$E$1:$E$100=$B$2)*(data!$C$1:$C$100=$A$2)*(data!$A$1:$A$100=$C2),ROW(data!$F$1:$F$100)),ROWS($B$1:B1)))

    returns only the correct first match for all three conditionals and "#NUM!" thereafter.

  5. #5
    Registered User
    Join Date
    12-31-2008
    Location
    Alaska, (not Anchorage)
    MS-Off Ver
    Excel 2010, 2016, and 365
    Posts
    78

    Re: Using AND to check 2 conditions...

    Got it.

    {=INDEX(data!$F$1:$F$100,SMALL(IF((data!$E$1:$E$100=$B$2)*(data!$C$1:$C$100=$A$2)*(data!$A$1:$A$100=$C2),ROW(data!$F$1:$F$100)),ROWS($B1:B1)))}

    Is there a more concise solution?

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using AND to check 2 conditions...

    Arrays are inefficient so you should only ever really use in moderation.

    Here it would seem as though a Pivot Table would be the perfect tool for analysis - easy to use, flexible and efficient - see attached for working example (Pivot sourced from Dynamic Named Range)

    Per your sample this is an XL2007+ file/pivot format.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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