excel-formulasumvlookup

Combining Sum with Vlookup


I have this data (table 1) :

Column A
1999
5000
6666

And there's table 2 :

Col.C | Col.D (range)|  Col.E (margin)
1000  | 1000 - 1260  |  830
1261  | 1261 - 1261  |  0
1262  | 1262 - 1513  |  830
1514  | 1514 - 1514  |  0
1515  | 1515 - 2522  |  830
2523  | 2523 - 2523  |  0
2524  | 2524 - 5044  |  960
5045  | 5045 - 5045  |  0
5046  | 5046 - 5549  |  960
5550  | 5550 - 5550  |  0
5551  | 5551 - 6558  |  960
6559  | 6559 - 6559  |  0
6560  | 6560 - 6999  |  960

The amount in Column A has a corresponding range (Column D), ie: 1999 is within range 1515 - 2522. So the margin is 830. My question is, how to sum all margin from table 1?

I already tried these formulas :

formula1 =SUM(VLOOKUP(VLOOKUP(A:A;C:D;2);D:E;2;0)) 
formula2 =SUMIF(D:D;VLOOKUP(A:A;C:D;2);E:E)

But the results only show the margin of the first row, not the total margin

Result formula1 : 830
Result formula2 : 830

It easier with helper column, and the results would look like this:

Col.A  | Margin
1999   | 830
5000   | 960
6666   | 960

The thing is, I don't want to use any helper column, since my data has 100,000 rows every month, the helper columns slowing down my excel because of the formula.

I just need to know the total margin (in this case, the total is 2750). Is there any way to get this result without helper column? All I can think is combining SUM/SUMIF and Vlookup. I've been searching for days, and I found many similar cases in this forum but to no avail.

Thanks in advance, any help is appreciated.


Solution

  • All these following three formulas worked for me, use anyone of the following:

    =SUM(LOOKUP(Table1[Column A],Table2))
    

    =SUM(XLOOKUP(Table1[Column A],
     --TEXTBEFORE(Table2[Col.D (range)]," "),
     Table2[Col.E (margin)],,-1))
    

    =SUM(SUMIF(Table2[Col.D (range)],
     LOOKUP(Table1[Column A],Table2[[Col.C]:[Col.D (range)]]),
     Table2[Col.E (margin)]))
    

    And even the formula used by has also worked when used with the help of TRIMRANGE() function or its reference operators:

    =SUM(DROP(VLOOKUP(VLOOKUP(A.:.A,C.:.D,2,1),D.:.E,2,0),1))
    

    or,

    =SUM(SUMIF(D.:.D,VLOOKUP(A.:.A,C.:.D,2,1),E.:.E))