+ Reply to Thread
Results 1 to 10 of 10

VLOOKUP() style but 3 value lookup

  1. #1
    Registered User
    Join Date
    02-24-2009
    Location
    Windsor, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    VLOOKUP() style but 3 value lookup

    Hi all,

    I have a table that has, amongst many columns, a year, month and a name column.

    I want to do a formula that takes in 3 values (name, year, month) and returns a sum of values found in a variety of other columnswhere these 3 values are matched.

    I would know how to do this in SQL but wonder if Excel can do this type of thing on one large data table?

    Cheers
    David
    Last edited by VBA Noob; 03-04-2009 at 10:02 AM.

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

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    Well you could use a Pivot Table obviously... this would be the best approach by far.

    You could also use Sumproduct ... given vague nature of question concering ranges I will give a generic solution

    D1:
    =SUMPRODUCT(($E$1:$E$100=$A1)*($F$1:$F$100=$B$1)*($H$1:$H$100=$C$1)*($J$1:$T$100))

    Where:

    E1:E100 holds Name and A1 Name of interest
    F1:F100 holds Year and B1 Year of interest
    H1:H100 holds Month and C1 Month of interest
    J1:T100 holds values to Sum

  3. #3
    Registered User
    Join Date
    02-24-2009
    Location
    Windsor, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    Thanks!

    Prob with pivot table is getting it into the format requested so would rather use the ad-hoc formulas like you mentioned above to get the data into the required presentation.

    Thanks again - I'll test it out

  4. #4
    Registered User
    Join Date
    02-24-2009
    Location
    Windsor, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    Sorry, one more thing...

    The J:T100 you state is a sum of a range - can I sum up individual values from 4 columns by using their table column name?

    Will the first 3 sets of brackets filter the table and then the last set will sum on the resulting filtered table so all I need to do is add the column heading references together (e.g. DataTbl['column1'] + DataTbl['column2'] + DataTbl['column3'])

    Do I make sense?




    Quote Originally Posted by DonkeyOte View Post
    Well you could use a Pivot Table obviously... this would be the best approach by far.

    You could also use Sumproduct ... given vague nature of question concering ranges I will give a generic solution

    D1:
    =SUMPRODUCT(($E$1:$E$100=$A1)*($F$1:$F$100=$B$1)*($H$1:$H$100=$C$1)*($J$1:$T$100))

    Where:

    E1:E100 holds Name and A1 Name of interest
    F1:F100 holds Year and B1 Year of interest
    H1:H100 holds Month and C1 Month of interest
    J1:T100 holds values to Sum

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

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    I confess that I don't use Tables feature so am not familiar with the syntax... in traditional setup:

    =SUMPRODUCT(($E$1:$E$100=$A1)*($F$1:$F$100=$B$1)*($H$1:$H$100=$C$1)*($J$1:$J$100+$M$1:$N$100+$P1:$P100+$T$1:$T$100))

  6. #6
    Registered User
    Join Date
    02-24-2009
    Location
    Windsor, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    What does the '*' do in your equation? Multiply?

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

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    Yes.

    Consider:

    ($E$1:$E$100=$A1) and ($F$1:$F$100=$B$1)

    The above will each generate an array of 100 Logical values, eg:

    {TRUE,FALSE,...,TRUE} and {FALSE,TRUE,...,TRUE}

    When calculating the Product one can view these "Pairs" as

    {TRUE * FALSE, FALSE * TRUE, ...., TRUE * TRUE}

    By * Logicals one coerces them to their integer equivalents (TRUE=1, FALSE=0 in Native XL)... such that the result of the above pairs becomes:

    {0, 0, ..., 1}

    Normally I prefer to use

    =SUMPRODUCT(--(A1:A100="x"),--(B1:B100="y"),C1:C100)

    as this is regarded as being slightly quicker and also little more flexible handling the summation range (C1:C100) HOWEVER this approach only works if the ranges are of equal dimensions which is not the case here (ie tests are 100R x 1C whereas results are say 100R x 4C) thus SUMPRODUCT via * is required.

    Does that make sense ?

  8. #8
    Registered User
    Join Date
    02-24-2009
    Location
    Windsor, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    Kind of!

    I can tell you it works!

    Here's my formula:

    =IFERROR(SUMPRODUCT((DataTbl[partner_manager]=PartnerSelect) * (DataTbl[year]=YearSelect) * (DataTbl[month]=MonthSelect) * (DataTbl[initial] + DataTbl[reinitial] + DataTbl[repeat] + DataTbl[credits] + DataTbl[chargebacks] + DataTbl[refunds] + DataTbl[sales_tax_vat])), "-")

    Using a table of data called DataTbl and the column headings are named between the square brackets [].

    The NameSelect fields are cells that have been named for easy reading sake.

    I have a further development on this now if you would be kind enough to help (very grateful so far by the way :D):

    The last sum returns a value in a mixture of ZAR currency (South Africa) and GBP.

    Could I extend this further to do a lookup on an xrates table based on the DataTbl[currency] column derived from the name/month/year filteration and apply the xrate to the value as it is being summed?

    This is delving deep now!!

    Cheers

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

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    In truth your life would be a lot easier if you added a further column to your table wherein via formulae you retrieve the appropriate fx rate based on the Date & Currency Code... your life then becomes much easier as you can simply * result by fx column (see red below)

    =IFERROR(SUMPRODUCT((DataTbl[partner_manager]=PartnerSelect) * (DataTbl[year]=YearSelect) * (DataTbl[month]=MonthSelect) * (DataTbl[initial] + DataTbl[reinitial] + DataTbl[repeat] + DataTbl[credits] + DataTbl[chargebacks] + DataTbl[refunds] + DataTbl[sales_tax_vat]) * (DataTbl[fx_rate])), "-")

    Make sense ?

  10. #10
    Registered User
    Join Date
    02-24-2009
    Location
    Windsor, England
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Help! Need a VLOOKUP() style but 3 value lookup

    Too right!! There's no reason why I can't do that!

    Thanks a lot

+ 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