VLOOKUP and SUMIF statement - any suggestions?

Nick_86

New Member
Joined
Jul 20, 2015
Messages
18
I have two tables in the same Sheet of a Workbook:

Table 1 (7 Columns (B-H), lots of rows):

COL B
PRD Identifier
COL C
CRD Identifier
COL D
House ID
COL E
Previous Reading Date
COL F
Current Reading Date
COL G
# Days
COL H
KWH Usage
A8054132A8054194A805413-Feb-1419-Apr-1465297
A8054194A8054206A805419-Apr-1420-Jun-1462353
A838072A8380104A838007-Feb-1410-Apr-1462492
A8380104A8380136A838010-Apr-1413-Jun-1464504
A8730112A8730154A873011-Feb-1415-Apr-1463738
A8730154A8730176A873015-Apr-1417-Jun-1463599

<colgroup><col span="2"><col><col><col><col><col></colgroup><tbody>
</tbody>

Table 2 (4 Columns (K-N, lots of rows):


COL K

HHD Identifier
COL L
House ID
COL M
Date

COL N

KWH Usage
A265911A26591/01/201511418
A265921A26592/01/201511269
A265931A26593/01/201512304
A265941A26594/01/201526629
A265951A26595/01/201535457
A265961A26596/01/201512280

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>


So Table one has each row containing a House ID, the Previous Read Date (PRD) and Current Read Date (CRD) of the electricity meter along with the number of days (CRD-PRD) and the KWH usage during that period. For ease of identifying a row I've created the PRD Identifier and CRD Idendifier which is a combination of the House ID & PRD (dd/mm only) and House ID 7 CRD (dd/mm only) respectively. i.e. for the first row: PRD Identifier = House ID & PRD dd/mm = A8054 & 13/02 = A8054132.

All the dates in Table 1 are in the range January to July 2014 but different periods of time.

Table 2 contains the same houses (House IDs) but the daily usage for each from January to July 2015. The excerpt of Table 2 above continues until 31/7/15 then goes to the next House ID and does the same from 1/1/15 to 31/7/15 and so on. The HHD Identifier = House ID & Date (dd/mm only).

So using an Identifier from one Table I am able to find the correct row for the same House and date (as year isn't taken into account).

What I want to do is have some kind of VLOOKUP and SUMIF statement for each row of Table 1 (say in Column I) so I can locate the 'Previous Read Date' (using the PRD Identifier) and the Current Read Date (using the CRD Identifier) in Table 2 and return the SUM of all the KWH Usage associated with that House between those dates (from the PRD to the CRD) so I can directly compare the same periods of time: the period in 2014 from Table 1 to the same period in 2015 from Table 2.

Can someone please suggest a way I could do this?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
If I have understood it correctly you should be able to do a sumproduct as such;

SUMPRODUCT(--(L:L=D2),--(E2<=M:M),--(F2>=M:M),N:N)
 
Upvote 0
I think I can do it with a SUMPRODUCT, but using =SUMPRODUCT(--(L:L=D2),--(E2<=M:M),--(F2>=M:M),N:N) returns #VALUE!

jono, I think you are correct, but how can I do a SUMPRODUCT with the 3 following conditions which if satisfied =1, and then return the sum of the values in Column N for each of those rows?

Conditions:
If any value in a row in Column L (i.e. L:L) = D2
AND
If any value in a row in Column M (ie. M:M) >= E2
AND
If any value in a row in Column M (i.e. M:M) <= F2

where E2 and F2 are dates and all the values in Column M are dates.

If the above 3 conditions are satisfied then:

Take the value in that row in Column N (i.e. N:N) and add that value to all of other values in Column N for which their rows satisfy the conditions.

i.e. Lets say rows 17-20 in the table (L1:N65535) satisfies all the conditions, so L17:L20 all have the same value as the value in cell D2 AND M17:M20 all have a date value that's greater than or equal to E2's date but also less than or equal to F2's date. So then the SUMPRODUCT will return (1*1*15)+(1*1*20)+(1*1*22)+(1*1*17) corresponding to cells (L17*M17*N17)+
(L18*M18*N18)+(L19*M19*N19)+(L20*M20*N20), where N17=15, N18=20, N19=22, N20=17. All the values/dates in L17:L20 and M17:M20 have satisfied the conditions so return the value 1. The value I want at the end of all of this example would then =15+20+22+17=74 (the sum of the values in N17-N20).

What does the -- mean/do in the above formula? Does it mean that the value of that variable become 1 if the statement is correct?

Any help would be much appreciated.




 
Upvote 0

Forum statistics

Threads
1,215,573
Messages
6,125,608
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top