+ Reply to Thread
Results 1 to 10 of 10

Excel 2007 : Using sumif with variable multipliers

Hybrid View

  1. #1
    Registered User
    Join Date
    03-15-2012
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    6

    Using sumif with variable multipliers

    I'm afraid there is an obvious and simple answer to my problem but I'm just not thinking of it. Here goes:

    I need a formula that provides the results of a sumif formula but has each component of the total multiplied by a factor that could vary for each item. Perhaps it could also be described as a sumproduct applied only to specific records. For example, in the two tables below I want to find (sumif?) the total of "C" as a taker in the top table times the tax rate of the givers shown in the bottom table. The answer expected for "C" is 90 (50+45). I need a solution that does not require adding a seperate column to calculate the tax for each row because the actual application of the formula will be in a large complex model that doesn't allow the necessary extra columns. I can't seem to nest a vlookup or other formula within sumif but I'm not convinced this is the answer anyway. Please help with suggestions.

    giver taker value
    A C 100
    B C 60
    B D 75

    Player tax%
    A 50%
    B 75%
    C 33%
    D 20%

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Using sumif with variable multipliers

    Assume that the first table (excluding headers) is in A2:C4 and second table is E2:F5 then try this formula for the required "C" total

    =SUMPRODUCT(SUMIF(E$2:E$5,A$2:A$4,F$2:F$5)*(B$2:B$4="C"),C$2:C$4)

    SUMIF effectively does the "lookup" to find the correct values from your second table.....see attached example
    Attached Files Attached Files
    Last edited by daddylonglegs; 03-15-2012 at 05:43 PM.
    Audere est facere

  3. #3
    Registered User
    Join Date
    03-15-2012
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Using sumif with variable multipliers

    Thanks DaddyLL. This does the trick on my simple example. It seems the solution was where I was looking for it but I still can't get my head around the steps in this formula. Any chance you can explain the logic? My next step is to apply this formula to the list @E2:E5 and net the giver/taker values such that A=(50) & B=(101.25) and the net for all = 0. Further, I will actually need to calculate the tax rate in column F from two other columns, say Prior year taxes / Prior year revenue. I think I can handle this if I can just grasp the logic in this sumproduct(sumif) solution you provided.

  4. #4
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Using sumif with variable multipliers

    where your data is in Col A,B,C and your tax rates are in Col E,F you can use the bellow:

    replace "A" with the reference to A in your results table

    =SUMIF(A:A,"A",C:C)*vlookup("A",E:F,2,0)

    if you attach a sample, i could give you this in use.
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  5. #5
    Registered User
    Join Date
    03-15-2012
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Using sumif with variable multipliers

    Thanks for the input Dgagnon. This solution is where I was when I hit a wall. The problem is that it counts at the takers rate, rather than the different givers rates. I am actually using this formula for part of the model. It just doesn't give the right answer when there are different tax rates.

  6. #6
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Using sumif with variable multipliers

    could you attach a worksheet with a few examples that would be more complex?

  7. #7
    Registered User
    Join Date
    03-15-2012
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Using sumif with variable multipliers

    Here is a slightly expanded sample based on the solution DLL provided
    Attached Files Attached Files

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Using sumif with variable multipliers

    As I said in my first post, SUMIF is really acting like a lookup formula here to return an "array" of results, corresponding to the tax % for each taker in the first table (effectively equivalent to a helper column). When you use this part

    =SUMIF(E$2:E$5,A$2:A$4,F$2:F$5)

    That returns an "array" of values, for each value in A2:A4 it sums F2:F5 when A2:A4 matches E2:E5. For example A2 is "A" so "A" is found in E2 and therefore the result is F2 (50%), so your array result looks like this

    {0.5;0.75;0.75}

    In the SUMPRODUCT that array is then multiplied by your value column only when taker column is also the right value

    VLOOKUP can't work here because it doesn't work with a range as the lookup value (to return an array) but LOOKUP is a possibility, e.g. this should also work

    =SUMPRODUCT(LOOKUP(A$2:A$4,E$2:F$5)*(B$2:B$4=A12),C$2:C$4)

    .....but for that to work A2:A4 must be sorted ascending (not sure that's the case in your real data) and any non-matching values would cause errors so I recommend sticking with SUMIF

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Using sumif with variable multipliers

    Can givers also be takers (or vice versa?)

    This formula should give you those results in J2:J5, using columns G and H values rather than the results in F

    =SUMPRODUCT(SUMIF(E$2:E$5,A$2:A$4,G$2:G$5)/SUMIF(E$2:E$5,A$2:A$4,H$2:H$5),(B$2:B$4=E2)-(A$2:A$4=E2),C$2:C$4)
    Last edited by daddylonglegs; 03-15-2012 at 07:18 PM.

  10. #10
    Registered User
    Join Date
    03-15-2012
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Using sumif with variable multipliers

    Fantastic! I was just about to write back explaining I was hitting the same issue with sumif not allowing internal formulas when your post came through. Not only does it seem to work perfectly, it is cleaner logic than I was going to use. I still need to get my head around the full logic as I use it for several areas of the model, but it looks like there is enough her for me to get the hang of it.

    To answer your question givers can be takers they just can't give to themselves...although I don't think it should matter. The real application of this is for exchange of items that have varied units of measure. One business unit may haul 3 tons per load and another hauls 4 tons per load. If I give a load from the first unit to the second it should only be for the 3 tons that existed in the haul to begin with. I thought I would find several other examples of this need in a web search but I didn't. Perhaps I just didn't understand the sumif array results. In any event I am truly appreciative of your time. I will check back tomorrow to close this as resolved once I check in the model.

    Thanks again.

+ 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