Sum Across Multiple Columns with date Critieria Across the header

ChetanPuri

Board Regular
Joined
Sep 5, 2018
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon Excel Team,

I need help with summing across Columns using both dates and Customer Code criteria. As you can see on Excel query Sheet 1, I have columns with Date Headers and underneath I have data, which I want to sum in sheet Column E, is there a formula where I can match the date and customer code in Column B of sheet 2 with Column B of Sheet 1 and it summs it by matching the header data and Colmn A dates in Sheet2. Any help with the formula is much appreciated.

Many thanks,

Regards,
Chetan
 

Attachments

  • Excel Query Sheet 2.jpg
    Excel Query Sheet 2.jpg
    119.1 KB · Views: 24
  • xecl Query Sheet 1.jpg
    xecl Query Sheet 1.jpg
    57.6 KB · Views: 26

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this starting in cell E2 and copy down. You will need to adjust the Query Sheet 2 range references.

Excel Formula:
=LET(
Nbr,B2,
Dt,A2,
Data,'Query Sheet 2'!$O$8:$AA$105,
Dts,Sheet1!$O$8:$AA$8,
Nbrs,TAKE(Data,,2),
SUM(FILTER(FILTER(Data,Nbrs=Nbr,""),Dt=Dts,"")))

This was done free form. I did not recreate your data. If you'd like to have the forum use some of your data, please use the xl2bb add in or post your data in a Table that can be copied from the screen.

Thanks in advance.
 
Upvote 0
Try this starting in cell E2 and copy down. You will need to adjust the Query Sheet 2 range references.

Excel Formula:
=LET(
Nbr,B2,
Dt,A2,
Data,'Query Sheet 2'!$O$8:$AA$105,
Dts,Sheet1!$O$8:$AA$8,
Nbrs,TAKE(Data,,2),
SUM(FILTER(FILTER(Data,Nbrs=Nbr,""),Dt=Dts,"")))

This was done free form. I did not recreate your data. If you'd like to have the forum use some of your data, please use the xl2bb add in or post your data in a Table that can be copied from the screen.

Thanks in advance.
Thank you Kindly, much appreciated.
 
Upvote 0
This formula may work better:
Excel Formula:
=SUM(LET(
Nbr,B2,
Dt,A2,
Data,'Query Sheet 2'!$O$9:$AA$105,
Dts,'Query Sheet 2'!$O$8:$AA$8,
Nbrs,'Query Sheet 2'!$B$9:$B$105,
FILTER(FILTER(Data,Dts=Dt,""),Nbrs=Nbr,"")))

Or this one, i'm sure there are others, as well:

Excel Formula:
=LET(
Nbr,B2,
Dt,A2,
Data,'Query Sheet 2'!$O$9:$AA$105,
Dts,'Query Sheet 2'!$O$8:$AA$8,
Nbrs,'Query Sheet 2'!$B$9:$B$105,
SUM(Data*(Dts=Dt)*(Nbrs=Nbr)))
 
Last edited:
Upvote 0
Given the apparent data structure in the images, I would go with a SUMIF

This is my sample data

ChetanPuri.xlsm
BOPQRSTUVWXYZAA
87/07/202314/07/202321/07/202328/07/20234/08/202311/08/202318/08/202325/08/20231/09/20238/09/202315/09/202322/09/202329/09/2023
9a4436384461444
10a2329913479382
11b8678573146138
12c4526913219597
13a5679166337825
14c8186838637347
15b2243211629885
16c6315659647547
17a6321413752943
Query Sheet 2



.. and results

ChetanPuri.xlsm
ABC
1
27/07/2023a17
37/07/2023b10
47/07/2023c18
57/07/2023d0
614/07/2023a16
714/07/2023c9
814/07/2023b8
914/07/2023d0
101/09/2023d0
111/09/2023a21
121/09/2023b6
Sheet1
Cell Formulas
RangeFormula
C2:C12C2=SUMIF('Query Sheet 2'!B$9:B$105,B2,INDEX('Query Sheet 2'!O$9:AA$105,0,MATCH(A2,'Query Sheet 2'!O$8:AA$8,0)))
 
Upvote 0
Given the apparent data structure in the images, I would go with a SUMIF

This is my sample data

ChetanPuri.xlsm
BOPQRSTUVWXYZAA
87/07/202314/07/202321/07/202328/07/20234/08/202311/08/202318/08/202325/08/20231/09/20238/09/202315/09/202322/09/202329/09/2023
9a4436384461444
10a2329913479382
11b8678573146138
12c4526913219597
13a5679166337825
14c8186838637347
15b2243211629885
16c6315659647547
17a6321413752943
Query Sheet 2



.. and results

ChetanPuri.xlsm
ABC
1
27/07/2023a17
37/07/2023b10
47/07/2023c18
57/07/2023d0
614/07/2023a16
714/07/2023c9
814/07/2023b8
914/07/2023d0
101/09/2023d0
111/09/2023a21
121/09/2023b6
Sheet1
Cell Formulas
RangeFormula
C2:C12C2=SUMIF('Query Sheet 2'!B$9:B$105,B2,INDEX('Query Sheet 2'!O$9:AA$105,0,MATCH(A2,'Query Sheet 2'!O$8:AA$8,0)))
Thank you that worked:


Book3
ABCDEFGHIJKLMNOPQRSTU
1Customer Code7-Jul-2314-Jul-2321-Jul-2328-Jul-234-Aug-2311-Aug-2318-Aug-2325-Aug-231-Sep-238-Sep-2315-Sep-2322-Sep-2329-Sep-236-Oct-2313-Oct-2320-Oct-2327-Oct-233-Nov-2310-Nov-2317-Nov-23
21000542864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.182864.18
3100054
41000552501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.422501.42
51000565007.9895007.9895007.9895007.9895007.9895007.98945007.98945007.98945007.9895007.9895007.98945007.98942861.7082
61000562146.28125007.9895007.9895007.9895007.9895007.9895007.98945007.9894
71000573931.992808.564
81000571123.4263931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.993931.99
910005812570.2512570.2512570.2512570.2512570.2512570.2512570.2512570.2512570.2512570.257183.0001
101000585387.2512570.2512570.2512570.2512570.2512570.2512570.2512570.2512570.2512570.25
111000596203.596203.596203.596203.596203.596203.596203.596203.596203.596203.593544.9086
121000592658.68146203.596203.596203.596203.596203.596203.596203.596203.596203.59
1310006054505450545054505450545054505450545054505450545054505450545054505450545054505450
141000617101.67101.67101.67101.67101.67101.67101.67101.67101.67101.67101.65072.5714
151000612029.02867101.67101.67101.67101.67101.67101.67101.67101.6
161000627963.527963.527963.527963.527963.527963.51997963.51997963.51997963.527963.527963.51997963.51997963.51997963.523412.937
171000624531.7497930.567930.567930.567930.567930.56
181000635870.0665870.0665870.0665870.0665870.0665870.06585870.06585870.06585870.0665870.0665870.06585870.06584192.9041
191000631711.93415991.7695991.7695991.7695991.7695991.7695991.76955991.7695
20100063
211000643906.653906.653906.653906.653348.557
22100064526.95863688.713688.713688.713688.713688.713688.713688.713688.713688.713688.713688.713688.713688.713688.713688.71
231000655450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.745450.74
24100065
251000668570.384897.36
261000664800.26911200.6311200.6311200.6311200.62711200.62711200.62711200.6311200.6311200.62711200.62711200.62711200.6311200.6311200.6311200.6311200.6311200.62711200.627
27100066
281000679297.199297.199297.199297.199297.199297.19019297.19019297.19019297.199297.199297.19019297.19019297.19019297.199297.199297.199297.199297.199297.19019297.1901
2910006810604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.9310604.93
301000694894.0594894.0594894.0594894.0594894.0594894.05884894.05884894.05884894.0594894.0594894.05884894.05884894.05884894.0594894.0594894.0594894.0594894.0594894.05884894.0588
311000706771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.8736771.873
321000707186.27
331000717965.8117965.8117965.8117965.8117965.8114551.8921
341000713413.91917965.81127965.81127965.8117965.8117965.81127965.81127965.81127965.8117965.8117965.8117965.8117965.8117965.81127965.8112
351000726510.346510.346510.346510.346510.346510.346510.346510.34
361000726981.16981.16981.09996981.09996981.09996981.16981.16981.16981.16981.16981.09996981.0999
37100073
381000734860.024860.024860.024860.024860.024860.01994860.01994860.01994860.024860.024860.01994860.01994860.01994860.024860.024860.024860.024860.024860.01994860.0199
39100074
401000743490.983490.983490.983490.983490.9801
411000743638.143638.143638.143638.143638.143638.143638.143638.143638.143638.143638.143638.14
421000747384.797384.79
431000754631.574631.574631.574631.571984.959
441000752663.9144661.854661.854661.854661.854661.854661.854661.854661.854661.854661.854661.854661.854661.854661.854661.85
451000765175.575175.575175.575175.575175.575175.575175.575175.575175.575175.575175.575175.572957.4686
461000762219.49865178.835178.835178.835178.835178.835178.835178.83
471000774794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.354794.35
481000784188.6034188.6034188.6034188.6034188.6034188.6033598.3719
491000784411.80123151.287
501000781260.5144411.84411.84411.84411.84411.84411.84411.84411.84411.84411.84411.8
511000796660.956660.956660.956660.956660.956660.94996660.94996660.94996660.956660.956660.94996660.94996660.94996660.956660.956660.956660.956660.956660.94996660.9499
521000814728.5534728.5534728.5534728.553
531000814917.524917.51994917.51994917.51994917.524917.524917.51994917.51994917.51994917.524917.524917.524917.524917.524917.51994917.5199
541000824210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.714210.71
55100083
561000834216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.414216.41
571000849980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.029980.02
581000855098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.995098.99
591000866411.836411.836411.836411.836411.836411.82986411.82986411.82986411.836411.836411.82986411.82986411.82986411.836411.836411.836411.836411.836411.82986411.8298
601000876657.2676657.2676657.2676657.2676657.2676657.26666657.26666657.26666657.2676657.2676657.26666657.26666657.26666657.2676657.2676657.2676657.2676657.2676657.2666
611000877176.65
621000887021.1817021.1817021.1817021.1817021.1817021.18067021.18067021.18067021.1817021.1817021.18067021.18067021.18067021.1817021.1817021.1817021.1817021.1817021.18067021.1806
631000895889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.035889.03
641000916433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.416433.41
651000926522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.556522.55
6610009350865086508650865086508650865086508650865086508650865086508650865086508650865086
671000948866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.148866.14
681000954632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.784632.78
691000964926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.754926.75
701000984186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.584186.58
711000996232.0766232.0766232.0766232.0766232.0766232.07626232.07626232.07626232.0766232.0766232.07626232.07626232.07626232.0766232.0766232.0766232.0766232.0766232.07626232.0762
72100099
73100100
7410010011474.21
751001003291.20911519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.2311519.23
76100172
7710017213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.7213577.72
781001859310.19310.19310.19310.19310.19310.09999310.09999310.09999310.19310.19310.09999310.09999310.09999310.19310.19310.19310.19310.19310.09999310.0999
791001945500.9795500.9795500.9795500.9795500.9795500.97885500.97885500.97885500.9795500.9795500.97885500.97885500.97885500.9795500.9795500.9795500.9795500.9795500.97885500.9788
801002294632.874632.874632.874632.874632.874632.874632.874632.874632.87
811002294632.874632.874632.874632.874632.874632.874632.874632.874632.874632.874632.87
82100239
83100239
8410023910768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.8110768.81
851002459268.69268.69268.69268.69268.69268.59999268.59999268.59999268.69268.69268.59999268.59999268.59999268.69268.69268.69268.69268.69268.59999268.5999
8610024611415.3711415.3711415.3711415.3711415.3711415.3711415.379784.6029
871002461717.197112020.3812020.3812020.3812020.3812020.3812020.3812020.3812020.3812020.3812020.3812020.3812020.38
88100247
8910024711583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.6911583.69
901002678173.168173.168173.164670.377
911002673502.7838173.168173.168173.168173.168173.168173.168173.168173.168173.168173.168173.168173.168173.168173.168173.168173.16
921002688936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.338936.33
931002692488.5532488.5532488.5532488.5532488.5532488.55322488.55322488.55322488.5532488.5532488.55322488.55322488.55322488.5532488.5532488.5532488.5532488.5532488.55322488.5532
94100270
9510027010972.4610972.4610972.4610972.4610972.4610972.4610972.4610972.46
9610027012715.0112715.0112715.00912715.00912715.00912715.0112715.0112715.0112715.0112715.0112715.00912715.009
971002715933.5175933.5175933.5175933.5175933.5175933.51695933.51695933.51695933.5175933.5175933.51695933.51695933.51695933.5175933.5175933.5175933.5175933.5175933.51695933.5169
98100271
9910027212232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2612232.2610484.79
1001002721703.95711927.711927.711927.711927.7
1011002735535.9895535.9895535.9895535.9895535.9895535.98875535.98875535.98875535.9895535.9895535.98875535.98875535.98873954.278
1021002731642.8315749.915749.915749.915749.915749.915749.91
103100273
1041003226275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.356275.35
105100322
10610032511314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.911314.9
10710032810695.5310695.5310695.5310695.5310695.5310695.5310695.5310695.5310695.5310695.5310695.5310695.5310695.5310695.539167.597
1081003281575.92611031.4811031.4811031.4811031.4811031.48
109100358
1101003589963.979963.979963.979963.979963.979963.96999963.96999963.96999963.979963.979963.96999963.96999963.96999963.979963.979963.979963.979963.979963.96999963.9699
11110035911016.6311016.6311016.6311016.6311016.6311016.6311016.6311016.6311016.6311016.6311016.6311016.6311016.634721.413
1121003596640.33111620.5811620.5811620.5811620.5811620.5811620.58
11310036328201.0628201.0628201.0628201.0628201.0628201.06
11410036329641.8829641.8829641.8829641.8829641.8829641.8829641.8829641.8829641.8829641.8829641.8829641.8829641.8829641.88
11510038067806780678067806780678067806780678067802905.7143
1161003804004.60577008.067008.067008.067008.067008.067008.067008.066006.9086
117100380969.315716785.21
1181003962963.12346913.95466913.9556913.9556913.95466913.95466913.95466913.9556913.9556913.9556913.9556913.9556913.95466913.9546
1191003972963.12346913.95466913.9556913.9556913.95466913.95466913.95466913.9556913.9556913.9556913.9556913.9556913.95466913.9546
120100397
1211004203852.098988.218988.218988.218988.21
122100420
123100433
124484191.2485563.2487066.2487066.2487241.4487067.53490991.52502793.05505524.9505524.9505655.25505752.99505789.16506284.2506725510807.4515682.5515682.5519397.28520140.05
Query Sheet 2
Cell Formulas
RangeFormula
B124:U124B124=SUM(B2:B123)


Book3
ABCDE
1DateCustomer CodeAR GLQuery Sheet 2
27-Jul-231000542,864.182,864.182,864.18
37-Jul-231000552,633.572,633.572,501.42
47-Jul-231000565,008.005,008.005,007.99
57-Jul-231000573,714.733,714.733,931.99
67-Jul-2310005812,592.4512,592.4512,570.25
77-Jul-231000596,334.266,334.266,203.59
87-Jul-231000605,449.285,449.285,450.00
97-Jul-231000616,210.116,210.117,101.60
107-Jul-231000628,383.658,383.657,963.52
117-Jul-231000636,124.736,124.735,870.07
127-Jul-231000643,292.983,292.983,906.65
137-Jul-231000655,739.635,739.635,450.74
147-Jul-231000668,961.578,961.579,697.63
157-Jul-231000679,789.949,789.949,297.19
167-Jul-2310006810,483.0510,483.0510,604.93
177-Jul-231000694,052.174,052.174,894.06
187-Jul-231000707,186.277,186.276,771.87
197-Jul-231000718,386.048,386.047,965.81
207-Jul-231000726,510.356,510.356,510.34
217-Jul-231000734,860.024,860.024,860.02
227-Jul-231000743,676.003,676.003,490.98
237-Jul-231000754,877.044,877.044,631.57
247-Jul-231000765,175.575,175.575,175.57
257-Jul-231000774,794.364,794.364,794.35
267-Jul-231000784,437.014,437.014,188.60
277-Jul-231000796,254.796,254.796,660.95
287-Jul-231000815,039.155,039.154,728.55
297-Jul-231000824,210.714,210.714,210.71
307-Jul-231000834,226.164,226.164,216.41
317-Jul-2310008410,508.9610,508.969,980.02
327-Jul-231000855,369.245,369.245,098.99
337-Jul-231000866,751.666,751.666,411.83
347-Jul-231000876,675.196,675.196,657.27
357-Jul-231000880.007,393.307,021.18
367-Jul-231000895,889.035,889.035,889.03
377-Jul-231000916,638.446,638.446,433.41
387-Jul-231000926,868.256,868.256,522.55
397-Jul-231000935,014.395,014.395,086.00
Query 1
Cell Formulas
RangeFormula
E2:E39E2=IFERROR(SUMIF('Query Sheet 2'!$A$2:$A$3000,'Query 1'!$B$2:$B$3000,INDEX('Query Sheet 2'!$B$2:$BA$123,0,MATCH('Query 1'!$A$2:$A$3000,'Query Sheet 2'!$1:$1,0)))," ")
 
Upvote 0
Thank you that worked:
Good news.

However, I don't see how Query 1 column E in your mini sheet is showing the results it is as the formula shown for that column is incorrect. :confused:
I think that part of the confusion with any checking that you have done is caused by the fact that you have so many identical values across a row in Query Sheet 2

=IFERROR(SUMIF('Query Sheet 2'!$A$2:$A$3000,'Query 1'!$B$2:$B$3000,INDEX('Query Sheet 2'!$B$2:$BA$123,0,MATCH('Query 1'!$A$2:$A$3000,'Query Sheet 2'!$1:$1,0)))," ")

SUMIF should have ranges that are the same size but those two red ranges are very different in size (number of rows).
Also your MATCH function is looking at the blue range so will find the column with the correct date. Suppose that match returns a '3' you would then be indexing column 3 of a range starting at column B (the second red one above). Column 3 of that red range is actually column 4 on the worksheet which would not be the column with the matching date.
An example of this with your data/formula is code 100074 for 7-Jul-23. Your results sheet shows 3490.98 but if you look at Query Sheet 2 for that code/date all the cells are blank meaning the result should be 0.

I would also highly recommend not using space characters for the IFERROR alternative and not using the sheet name that the formula is on (Query 1) within the formula as that can lead to incorrect results in some circumstances.

I believe that your formula for A2 should be this, copied down
=IFERROR(SUMIF('Query Sheet 2'!$A$2:$A$3000,B2,INDEX('Query Sheet 2'!$A$2:$BA$3000,0,MATCH(A2,'Query Sheet 2'!$1:$1,0))),"")
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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