Combine 2 sumproducts from different sheets and SUM(OFFSET(INDIRECT(ADDRESS(MATCH(CONCATENATE))) combination

mbthemis

New Member
Joined
Sep 29, 2014
Messages
9
Hi to all, and thank you for all the great solutions that you provide in this forum.

I need to calculate the following in excel 2013 win7:
Data of the 1st sheet will be pasted from another software. In it there will be data of different customers. In B column there will be CODE of the expenses and in F column the SUM. CODE of expenses will be grouped into CODE CATEGORIES in sheet2. I need to calculate for every single customer by each code category the sum .
1-So i must generate a customers list (by its vat number) from sheet 1. (i can do it manually if it cant be done automatically)
2.-I must specify the range of cells that belong to each customer and contain their data. I have come up with this formula with which i can play : =SUM(OFFSET(INDIRECT(ADDRESS(MATCH(CONCATENATE("FM: ";M1);E:E;0);5));0;0;ABS(MATCH(CONCATENATE("FM: ";M2);E:E;0)-MATCH(CONCATENATE("FM: ";M1);E:E;0));2))
the vat is given by the software in "FM: 1015151515" format.

3. In sheet 2 i have grouped each expense code by category and each category has been marked by a number (i have done this by color and a macro command but since different excel versions show colors differently, in the example the categories are numbers).

4. I have tried with sumproduct and sumif as i show you in the table below but without success. I need to calculate somehow for each client (shorted by vat numbers), the sum of expenses in sheet1 column F, (with the following conditions) by each category at sheet 2 (H1 to M1) from the expense codes in the sheet1 that belong to this category (column B in sheet1 that matches the column A in sheet2. All this must include the offset function probably so as to understand the excel how many rows belong to each client.

These are the sheets -> with the formulas:
sheet 1 starting from A1:
----------------------------------------------------------------
COMPANYFM: 149186824VAT NUMBERS FOR TEST
CREDITDEBITSUM149186824
114.00.0000DESCRIPTION338,050338,05102958444
220.00.0000DESCRIPTION93,71093,71
320.00.0013DESCRIPTION112,090112,09SUM BY OFFSET TEST
462.03.0123DESCRIPTION47,02047,02=SUM(OFFSET(INDIRECT(ADDRESS(MATCH(CONCATENATE("FM: ";H2);E:E;0);5));0;0;ABS(MATCH(CONCATENATE("FM: ";H3);E:E;0)-MATCH(CONCATENATE("FM: ";H2);E:E;0));2))
562.04.0000DESCRIPTION1.008,8001.008,80
663.04.0000DESCRIPTION290,220290,22
763.98.0000DESCRIPTION33,72033,72
864.00.1023DESCRIPTION2850285
964.08.0023DESCRIPTION55,29055,29
1064.98.0000DESCRIPTION74,95074,95
1164.98.0023DESCRIPTION1.460,0401.460,04
1273.10.0013DESCRIPTION0160,04-160,04
1373.10.0023DESCRIPTION01.217,15-1.217,15
1475.00.0000DESCRIPTION01.020,00-1.020,00
1575.00.0023DESCRIPTION01.094,00-1.094,00
---------------
DATA
COMPANYFM: 102958444
CREDIT DEBITSUM
161.92.0000DESCRIPTION451,420451,42
264.98.0000DESCRIPTION0,300,3

<colgroup><col span="7"><col></colgroup><tbody>
</tbody>
--------------------------------------------------------------------------------

sheet2 starting from A1
---------------------------------------------------------------------------------
CATEGORY DESCRIPTIONSDESCRIPTIONDESCRIPTIONDESCRIPTIONDESCRIPTIONDESCRIPTIONDESCRIPTION
CATEGORY CODES65535
102133169944516959288633424893969910
CATEGORIZATION OF EXPENSE CODESsumif test for all=SUMIF($C:$C;H2;$D:$D)
205,8
0000
DESCRIPTIONCATEGORY CODESUM BY CATEGORY ON ALL CLIENTStest sumproduct for allVAT NUMBERS PER CLIENT
DESCRIPTION65535=SUMIFS(Sheet1!F:F;Sheet1!B:B;A5)
=SUMPRODUCT((Sheet1!$F:$F);--(A5=Sheet1!$B:$B))
FM: 149186824=SUMPRODUCT(--($C$1:$C$10000=H$2);(Sheet1!$F$1:$F$10000);-($A$1:$A$10000=Sheet1!$B$1:$B$10000))
00000
DESCRIPTION655350FM: 102958444000000
DESCRIPTION655350more vat…
DESCRIPTION655350more vat…
DESCRIPTION655350more vat…
DESCRIPTION655350more vat…
DESCRIPTION1021331693,71more vat…
DESCRIPTION102133160
DESCRIPTION10213316112,09
DESCRIPTION102133160
DESCRIPTION102133160
DESCRIPTION102133160
DESCRIPTION99445160
DESCRIPTION99445160
DESCRIPTION99445160
DESCRIPTION99445160
DESCRIPTION99445160
DESCRIPTION255
0
DESCRIPTION33424890
DESCRIPTION33424890
DESCRIPTION33424890
DESCRIPTION33424890

<colgroup><col><col><col span="2"><col><col><col span="6"></colgroup><tbody>
</tbody>
------------------------------------------------------------------------------------------------------------------------------------------------
I have put the formulas in sheet1 in cell H6 and in sheet2 in cells D5, E5, H5 and H3 please copy paste the above to see it in an excel.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Ok ill try Aladin,

so in sheet1 we start from A1 . This sheet contains the pasted data from hundreds of clients. The rows for each client are variable and can be a few or many.
------------------------------------------------------------------
COMPANYFM: 111111111
CREDITDEBITSUM
114.00.0000DESCRIPTION338,050338,05
220.00.0000DESCRIPTION93,71093,71
320.00.0013DESCRIPTION112,090112,09
462.03.0123DESCRIPTION47,02047,02
562.04.0000DESCRIPTION1.008,8001.008,80
663.04.0000DESCRIPTION290,220290,22
763.98.0000DESCRIPTION33,72033,72
864.00.1023DESCRIPTION2850285
964.08.0023DESCRIPTION55,29055,29
1064.98.0000DESCRIPTION74,95074,95
---------------
DATA
COMPANYFM: 222222222
CREDITDEBITSUM
120.00.0000DESCRIPTION10000010000
264.98.0000DESCRIPTION200002000

<tbody>
</tbody>
-------------------------------------------------------------------------------
sheet2 contains the categorization of the expenses codes in columns A,B,C AND IN D column there is the sum for all clients by each expense code. In H6 and H7 and so on for each client i must calculate for each category the sum .
----------------------------------------------------------------------------------------------
CATEGORY DESCRIPTIONSDESCRIPTIONDESCRIPTIONDESCRIPTIONDESCRIPTIONDESCRIPTION
CATEGORY CODES6553510213316994451633424893969910
CATEGORIZATION OF EXPENSE CODESsumif test for all clients10431,76159,111299,02318,722130,24
EXPENSE CODEDESCRIPTIONCATEGORY CODESUM BY CATEGORY ON ALL CLIENTStest sumproduct for allVAT NUMBERS PER CLIENTsum per category by clientsum per category by clientsum per category by clientsum per category by clientsum per category by client
14.00.0000DESCRIPTION65535338,05338,05FM: 149186824431,76159,111299,02318,72130,24
20.00.0000DESCRIPTION6553510093,71FM: 102958444100000002000
20.00.0013DESCRIPTION10213316112,09more vat…
62.03.0123DESCRIPTION1021331647,02
62.04.0000DESCRIPTION99445161008,8
63.04.0000DESCRIPTION9944516290,22
63.98.0000DESCRIPTION334248933,72
64.00.1023DESCRIPTION3342489285
64.08.0023DESCRIPTION396991055,29
64.98.0000DESCRIPTION39699102074,95

<tbody>
</tbody>
-----------------------------------------------------------------------------------
the results next to every vat is what i need to get by the new formula. Also the sumproduct really slows down my pc, but it might be inevitable if i need get this through.
 
Last edited:
Upvote 0
Is this too big also, or the problem is generally too difficult?

Did i describe the problem in a comprehensive way?
 
Upvote 0
Is this too big also, or the problem is generally too difficult?

Did i describe the problem in a comprehensive way?

Big indeed. Try to post smaller samples along with the expected/desired results, manually calculated using the samples.
 
Upvote 0
ΟΚ :) another try.
Sheet 1 are the DATA. Each client is separated by VAT code.
---------------------------------------------
VATVAT: 111111111
EXPENSES CODESUM
14.00.00001000
20.00.00001000
20.00.0013500
62.03.0123500
VATVAT: 222222222
EXPENSES CODESUM
20.00.00005000
62.03.01232000

<colgroup><col><col></colgroup><tbody>
</tbody>
-------------------------------------
Sheet2 contains the categorization of expenses and the calculations per VAT
---------------------------------------
CATEGORIZATION OF EXPENSE CODESCATEGORY CODES65535
10213316
EXPENSE CODECATEGORY CODE
14.00.000065535 VAT NUMBERS PER CLIENTsum per category by clientsum per category by client
20.00.000065535 VAT: 149186824
20001000
VAT: 102958444
50002000
20.00.001310213316more vat…
62.03.012310213316

<colgroup><col><col><col><col><col span="2"></colgroup><tbody>
</tbody>
----------------------------------------------------
so i need a formula that will sum the cells of each client in sheet1 separately, and then give me the sum by each expense category in sheet2. for example for the category 65535 the sum for the first client is 2000 (1000+1000) and for the second is 5000, while for the category 10213316 the sum for the 1st client is 1000(500+500) while for the second one is 2000.

I hope there is a solution.
 
Upvote 0
Any ideas someone? Aladin is this comprehensible?

I just copied the samples into Excel. Alas, I fail see the correlation between DATA and Sheet2... For example, the VAT: numbers of DATA do not occur on Sheet2. The field names do not provide any clue on the correlation one would expect.

As a side note but an important one from a processing point of view...

Records can better be headed with the VAT: number, thus repeated. Thus not:

VATVAT: 111111111
EXPENSES CODESUM
14.00.00001000
20.00.00001000
20.00.0013500
62.03.0123500
VATVAT: 222222222
EXPENSES CODESUM
20.00.00005000
62.03.01232000

<COLGROUP><COL style="WIDTH: 130pt; mso-width-source: userset; mso-width-alt: 6144" width=173><COL style="WIDTH: 138pt; mso-width-source: userset; mso-width-alt: 6542" width=184><TBODY>
</TBODY>


Rather...

VATEXPENSES CODESUM
11111111114.00.00001000
11111111120.00.00001000
11111111120.00.0013500
11111111162.03.0123500
22222222220.00.00005000
22222222262.03.01232000

<COLGROUP><COL style="WIDTH: 74pt; mso-width-source: userset; mso-width-alt: 3498" width=98><COL style="WIDTH: 137pt; mso-width-source: userset; mso-width-alt: 6513" width=183><COL style="WIDTH: 70pt; mso-width-source: userset; mso-width-alt: 3299" width=93><TBODY>
</TBODY>
 
Upvote 0
Aladin you are correct . when i tried to simplify the data i forgot to change the vat in sheet 2 . Unfortunatelly i will have no control in data sheet1. So the correlation that has to be made is to calculate for every vat the expenses code that belong to each category.For example for VAT 111111111 the sum of category 65535 will lookup in sheet1 only the 1000+1000 of the expense code 14.00.0000 and 20.00.0000 that belong to this category. When i try to sumif or sumproduct i cant do simultaneus calculation for all the expense codes of the category 65535. The calculation per expense code is easy, but i need it to be done automatically for all the codes that belong to each category per vat.
Thank you for giving the effort and sorry for the mistake.
 
Upvote 0
i found a way to make the list of vat numbers from sheet1 to appear in sheet2
so in cell D9 of sheet2 the formula is
=INDEX(Sheet1!$B:$B;MATCH(0;COUNTIF(Sheet2!$D$8:$D8;Sheet1!$B$1:$B$11)+(LEFT(Sheet1!$B$1:$B$11;2)<>Sheet1!$H$4);0);1)

instead of ENTER i hit ctrl+shift+enter to make it an array.
This part of the formula (Sheet2!$D$8:$D8;Sheet1!$B$1:$B$11) gives unique distinct values but to work a previous cell than the one you put the formula to must be in it (p.e. D8 inside the formula and the cell that the formula sits to be D9).

The second part of count if works opposite than the formula (LEFT(Sheet1!$B$1:$B$11;2)<>Sheet1!$H$4) . It searches for the first 2 letters of cell H4 (it is the cell that contains your search criteria p.e. VAT), and then it lists the matching data (the fact that has <> instead of = somehow works in reverse).

when i scroll it down i get all vat listed in sheet1.

Now for the hard part of getting results per vat and category, i am still working hard on it. For now i find it easier if i use an index match formula next to the expense codes in sheet1 and get each ones category then the sumif in sheet2 is working (although i am not fully satisfied with it because it is not a single formula).
 
Upvote 0

Forum statistics

Threads
1,216,074
Messages
6,128,653
Members
449,462
Latest member
Chislobog

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