Nested double vlookup and match function?

donny_benjamin

New Member
Joined
May 13, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi Everyone,

It's my first time posting and any help with my dilemma will be much appreciated! :)
I'm working on a new sales report for management. Since it will be updated on a regular basis, I am trying to automate it as much as possible.

My raw data is sorted by month then category instead of category and month (Figure 1, C1 : N2). I created another worksheet to group the categories by month. The challenge has been to find a formula that will retrieve the figures from the raw data tab into the new worksheet. I've tried vlookup, double vlookup, sumifs, and sumproduct functions. I also tried using a helper by combining the month and categories together but to no avail so I created a pivot table instead.

Now I need to create a summary sheet that will retrieve the data by based on month, category (Act, Fcst, etc.), Region and Product and then add a YTD total as show in Figure 3.

Thank you in advance for your help!


Figure 1
1589415409125.png


Figure 2
1589415371421.png


Figure 3
1589415909940.png
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Give this try to see if it gives the results expected:
Book1
ABCDEFGHIJ
1MarMTD MarYTD Mar
2Sys 1 ActFcstBudPYActFcstBudPY
3N. America1054420151319
4LATAM2310114171913
5EMEA576520181120
6APAC499111272211
7
8Sys 2
9N. America684714221618
10LATAM971224131517
11EMEA9117157922
12APAC389710232017
Sheet1
Cell Formulas
RangeFormula
B1B1="MTD "&A1
G1G1="YTD "&A1
B3:E6B3=SUMPRODUCT((Data!$A$3:$A$18=$A3)*(Data!$B$3:$B$18=$A$2)*(Data!$C$1:$N$1=$A$1)*(Data!$C$2:$N$2=B$2)*(Data!$C$3:$N$18))
G3:J6G3=SUMPRODUCT((Data!$A$3:$A$18=$A3)*(Data!$B$3:$B$18=$A$2)*(Data!$C$2:$N$2=G$2)*(Data!$C$3:$N$18))
B9:E12B9=SUMPRODUCT((Data!$A$3:$A$18=$A9)*(Data!$B$3:$B$18=$A$8)*(Data!$C$1:$N$1=$A$1)*(Data!$C$2:$N$2=B$2)*(Data!$C$3:$N$18))
G9:J12G9=SUMPRODUCT((Data!$A$3:$A$18=$A9)*(Data!$B$3:$B$18=$A$8)*(Data!$C$2:$N$2=G$2)*(Data!$C$3:$N$18))


Book1
ABCDEFGHIJKLMN
1JanJanJanJanFebFebFebFebMarMarMarMar
2RegionProductsActFcstBudPYActFcstBudPYActFcstBudPY
3N. AmericaSys 1 6419468610544
4N. AmericaSys 27525191066847
5N. AmericaSys 3291949244596
6N. AmericaSys 41073577235919
7LATAMSys 1 9945355723101
8LATAMSys 210410652499712
9LATAMSys 319823134105102
10LATAMSys 43641061010578710
11EMEASys 1 744987165765
12EMEASys 2255941369117
13EMEASys 34386109192776
14EMEASys 491071410528132
15APACSys 1 1104868924991
16APACSys 2173768833897
17APACSys 32145948108493
18APACSys 4842598211577
Data
Cell Formulas
RangeFormula
C3:N18C3=RANDBETWEEN(1,10)
 
Upvote 0
Hi Kirk,
I'm working on it now. Trying to make sense of the formulas in the meantime. Thank you so very much for your help and quick response. Will report back with the results soon.
 
Upvote 0
Hi Kirk,
Your formulas for MTD work flawlessly. For YTD, the formula works but when I select a different month, the totals don't change. For example, if I change the month to Feb, I should have 10 units in for System 1 in N. America instead of 20. I tried to add a sumif into the formula but obviously it did not work. Any thoughts? Thank you!
 
Upvote 0
I'm looking...sorry about the oversight. I stripped out the month altogether in that formula, but should have tweaked it.
 
Upvote 0
Give this a try...a bit more convoluted than I anticipated, but I think it should work:
Book1
ABCDEFGHIJ
1FebMTD FebYTD Feb
2Sys 1 ActFcstBudPYActFcstBudPY
3N. America46861010915
4LATAM35571214912
5EMEA87161511515
6APAC68927181310
7
8Sys 2
9N. America191068141211
10LATAM52491561415
11EMEA413666815
12APAC68837151110
sumproduct-2way
Cell Formulas
RangeFormula
B1B1="MTD "&A1
G1G1="YTD "&A1
B3:E6B3=SUMPRODUCT((Data!$A$3:$A$18=$A3)*(Data!$B$3:$B$18=$A$2)*(Data!$C$1:$N$1=$A$1)*(Data!$C$2:$N$2=B$2)*(Data!$C$3:$N$18))
G3:J6G3=SUMPRODUCT((Data!$A$3:$A$18=$A3)*(Data!$B$3:$B$18=$A$2)*(MONTH(DATEVALUE(Data!$C$1:$N$1&" 1"))<=MONTH(DATEVALUE($A$1&" 1")))*(Data!$C$2:$N$2=G$2)*(Data!$C$3:$N$18))
B9:E12B9=SUMPRODUCT((Data!$A$3:$A$18=$A9)*(Data!$B$3:$B$18=$A$8)*(Data!$C$1:$N$1=$A$1)*(Data!$C$2:$N$2=B$2)*(Data!$C$3:$N$18))
G9:J12G9=SUMPRODUCT((Data!$A$3:$A$18=$A9)*(Data!$B$3:$B$18=$A$8)*(MONTH(DATEVALUE(Data!$C$1:$N$1&" 1"))<=MONTH(DATEVALUE($A$1&" 1")))*(Data!$C$2:$N$2=G$2)*(Data!$C$3:$N$18))
 
Upvote 0
Hi Kirk,
So sorry for my late response. Thank you so much for the updated formula. For some reason, the YTD formulas like the one in G3, does not calculate. Instead it brings the number for that particular month. I created a simple table like yours and the formulas work flawlessly but I can't get it to work in my spreadsheet. I'm stomped yet again.
 
Upvote 0
Interesting...so the B3 formula works:
=SUMPRODUCT((Data!$A$3:$A$18=$A3)*(Data!$B$3:$B$18=$A$2)*(Data!$C$1:$N$1=$A$1)*(Data!$C$2:$N$2=B$2)*(Data!$C$3:$N$18))
and the G3 formula returns the month number?...So if you enter "Mar" in A1, you get 3 somewhere? The G3 formula is:
=SUMPRODUCT((Data!$A$3:$A$18=$A3)*(Data!$B$3:$B$18=$A$2)*(MONTH(DATEVALUE(Data!$C$1:$N$1&" 1"))<=MONTH(DATEVALUE($A$1&" 1")))*(Data!$C$2:$N$2=G$2)*(Data!$C$3:$N$18))

The difference between these formulas is this portion in the G3 formula, which is absent in the B3 formula:
(MONTH(DATEVALUE(Data!$C$1:$N$1&" 1"))<=MONTH(DATEVALUE($A$1&" 1")))*(Data!$C$2:$N$2=G$2)

First let's confirm that you're using the same column headings above the MTD block and the YTD block...in other words, I see Act, Fcst, Bud, and PY. Are these the same between both blocks?
If so, that rules out the B$2 and G$2 terms in the formulas, leaving only this:
(MONTH(DATEVALUE(Data!$C$1:$N$1&" 1"))<=MONTH(DATEVALUE($A$1&" 1")))
I suspect this is the issue. On your "Data" worksheet, what are the column headings?...are you using three letter abbreviations for the months: "Jan", "Feb", etc.

If you click in G3 (upper left corner of the first YTD block, go to the formula bar and select with the mouse the following:
DATEVALUE(Data!$C$1:$N$1&" 1")
then hit F9 and see if an array appears in the formula bar...something looking like this:
{43831,43831,43831,43831,43862,43862,43862,43862,43891,43891,43891,43891}
**** Hit Esc to cancel out of this, otherwise you'll overwrite the formula ****

Then do the same thing with:
DATEVALUE($A$1&" 1")
Do you see something like this: {43831}
**** and hit Esc again ****

Your numbers may be different...this is the date of January 1, 2020...I have "Jan" in cell A1 so this part of the formula converts the month abbreviation to a numeric value so that we can determine whether one date comes before another.

If there are no surprises, copy the first formula that gives an unexpected result and post back with it. You might want to load up the XL2BB add-in (see link in my signature block) to copy a small section of your worksheet for posting. Speaking of that, have you tried copying directly from my post #6? Click on the clipboard icon in the upper left at the intersection of rows and column labels (between the 1 and A) and then paste directly into a blank worksheet in cell A1.
 
Upvote 0
Hi Kirk,
Thank you for your feedback. I've tried everything that you suggested but somewhere along the line I'm making a mistake and I can't figure it out. I've even tried adding pivot tables and helper cells to make the formulas work but with limited success. The biggest challenge is the YTD. Below is a sample as you suggested. Thank you again for all your help.

Cell Formulas
RangeFormula
A4A4=VLOOKUP(A2,Mapping!$B$24:$C$35,2)
D5D5="MTD "&VLOOKUP($A$2,Mapping!$B$24:$C$35,2,0)
O5O5="YTD "&VLOOKUP($A$2,Mapping!$B$24:$C$35,2,0)
D7:G14D7=SUMPRODUCT((Data!$B$4:$B$39=Template!$A$5)*(Data!$A$4:$A$39=Template!$A7)*(Data!$C$2:$AX$2=Template!$A$4)*(Data!$C$3:$AX$3=Template!D$4)*(Data!$A$4:$AX$39))
D15:G15,O27:R27,D27:G27,O15:R15D15=SUM(D7:D14)
O7:R14O7=SUMPRODUCT((Data!$B$4:$B$39=Template!$A$5)*(Data!$A$4:$A$39=Template!$A7)*(MONTH(DATEVALUE(Data!$C$2:$AX$2&"1"))<=MONTH(DATEVALUE(Template!$A$4&"1")))*(Data!$C$3:$AX$3=Template!O$4)*(Data!$C$4:$AX$39))
D17,O17D17=D$5
D19:G26D19=SUMPRODUCT((Data!$B$4:$B$39=Template!$A$17)*(Data!$A$4:$A$39=Template!$A19)*(Data!$C$2:$AX$2=Template!$A$4)*(Data!$C$3:$AX$3=Template!D$4)*(Data!$A$4:$AX$39))
O19:R26O19=SUMPRODUCT((Data!$B$4:$B$39=Template!$A$17)*(Data!$A$4:$A$39=Template!$A19)*(MONTH(DATEVALUE(Data!$C$2:$AX$2&"1"))<=MONTH(DATEVALUE(Template!$A$4&"1")))*(Data!$C$3:$AX$3=Template!O$4)*(Data!$C$4:$AX$39))
Cells with Data Validation
CellAllowCriteria
A2List=Mapping!$B$23:$B$32



Sample.xlsx
ABCDEFGHIJKLMN
2MonthJanJanJanJanFebFebFebFebMarMarMarMar
3RegionProduct LineActual UnitsProj2 UnitsBudget UnitsPY Units Actual UnitsProj2 UnitsBudget UnitsPY Units Actual UnitsProj2 UnitsBudget UnitsPY Units
4CanadaSys A72047431215141114
5CanadaSys B331219216420629
6CanadaSys C16782331295141414
7CanadaProduct 1111531015222023197
8CanadaProduct 2312131217201414961119
9CanadaProduct 3616155318191617
10CSASys A71986520151510989
11CSASys B1461816811141201251
12CSASys C610111520965167213
13CSAProduct 14108761715201111184
14CSAProduct 21332048172020111757
15CSAProduct 31065201810615151621
16EMASys A5312561561918161313
17EMASys B1251062172016131922
18EMASys C1911210172121172019
19EMAProduct 11310121387811819165
20EMAProduct 295715191231012122
21EMAProduct 3131218181919616198125
22Greater ChinaSys A20616161510121918966
23Greater ChinaSys B431518336129818
24Greater ChinaSys C119113412369141518
25Greater ChinaProduct 12241641991337211
26Greater ChinaProduct 293148182157157197
27Greater ChinaProduct 321151681721662031
28Latin AmericaSys A10619811212166613
29Latin AmericaSys B61917852079131651
30Latin AmericaSys C171721151862209218
31Latin AmericaProduct 12021018135411181712
32Latin AmericaProduct 220613633174161678
33Latin AmericaProduct 3171516203718851699
34USSys A720101013414201418214
35USSys B142014141612119721512
36USSys C201212111117641281119
37USProduct 11121724218111412162
38USProduct 24115121141391016413
39USProduct 311121911171561352167
Data
 
Upvote 0
Do you have a small sample of the Mapping sheet? I'd like to confirm a few entries.
 
Upvote 0

Forum statistics

Threads
1,215,366
Messages
6,124,516
Members
449,168
Latest member
CheerfulWalker

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