Summing cell values from multiple sheets where both row and column criteria qualifies

sunnyk

New Member
Joined
Jan 4, 2017
Messages
5
Hi MrExcel community,

I will highly appreciate any help with the following.

I am trying to fetch sum of values in multiple sheets where a row header match and a column header match criteria holds true (similar to a matrix, one each across multiple tabs).

I have defined the Sheet names in a table Table1 (Sheet1, Sheet2, Sheet3, etc.).
I want to sum the values in each of these sheets where row header (column A) contains ABC and column header (row 1) contains XYZ.

I tried the following 2 formulas but none worked:


Formula 1:
=IFERROR(SUMPRODUCT(INDEX(INDIRECT("'"&Table1[SheetNames]&"'!$B$2:$E$10"),MATCH(“ABC”,INDIRECT("'"& Table1[SheetNames]&"'!$A$2:$A$10"),0),MATCH(“XYZ”,INDIRECT("'"& Table1[SheetNames]&"'!$B$1:$E$1"),0))),)

Result: This formula when entered as an array formula (Ctrl+Shift+Enter) only looks at the Sheet1 (Array within Indirect doesn’t expand)

Formula 2:
=SUMPRODUCT((T(INDIRECT("'"& Table1[SheetNames]&"'!$A$2:A10"))=”ABC”)*(T(INDIRECT("'"& Table1[SheetNames]&"'!$B$1:$E$1"))=”XYZ”),N(INDIRECT("'"& Table1[SheetNames]&"'!$B$2:$E$10")))

Result: This formula when entered only look for the first cell in the cell range to compare (i.e.; only references A2 within each sheet for ABC, and only references B1 within each sheet for XYZ) – rest of the cells in array are not compared at all

Thanks a Ton in advance!!!

PS: I ended up posting this question in 3 related threads - kindly ignore those duplicate posts. As recommended by Mark858, I am creating this new thread and have requested deletion for those duplicate posts in other threads. Thanks!!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I'm going to start looking at this and trying to understand your question. If you could upload a sample workbook showing what you want, someone will likely be able to find the answer to your question more quickly.
 
Upvote 0
So your table contains range address like "Sheet32!B5:B55"? Stored as text?

trying to fetch sum of values in multiple sheets
In general your formula will refer to different sheets? Or within one cell you need to sum values from different sheets?

Here's a starting point. Tell me what's right or wrong...

Code:
=SUM(
    INDIRECT(
        INDEX(
            Table1[#All],
            MATCH(
                "ABC",
                Table1[Col1],
                0
            ),
            MATCH(
                "ABC",
                Table1[#Headers],
                0
            )
        )
    )
)
 
Upvote 0
Thanks ping_pong! The following example demonstrates the problem. Let me know if you need further information. Thanks so much for your help!!

Summary TableSTUTUVXYZZZZ
AAATable on left summarizes total for each row/column combination

This is where I want to use formula to sumproduct values for all row/column combinations from multiple tabs in the workbook.
AAB
ABB
ABC
BCD
DEF
HIJ
KLM
MMM

<tbody>
</tbody>


Table 1 for sheet names (used in Indirect clause to dynamically reference the sheets)
SheetNames
Sheet1
Sheet2
Sheet3
Sheet4

<tbody>
</tbody>

Data in Sheet1 (A1:E6)
STUTUVXYZZZZ
ABB10899
ABC11769
BCD1211410
DEF1191111
HIJ9547

<tbody>
</tbody>

Data in Sheet2 (A1:D7)
STUXYZZZZ
ABC9810
BCD6711
DEF41112
HIJ11911
KLM459
MMM6711

<tbody>
</tbody>

Data in Sheet3 (A1:D6)
TUVXYZZZZ
BCD9109
DEF9116
HIJ10124
KLM111111
MMM794

<tbody>
</tbody>

Data in Sheet4 (A1:C4)
STUTUV
AAA89
ABC79
HIJ1110

<tbody>
</tbody>
 
Upvote 0
Control+shift+enter, not just enter:

=SUM(IF(T(INDIRECT("'"&Table1[SheetNames]&"'!A2:A10"))="ABC",IF(T(INDIRECT("'"&Table1[SheetNames]&"'!B1:E1"))="XYZ",N(INDIRECT("'"&Table1[SheetNames]&"'!B2:E10")))))
 
Upvote 0
Thank you so much Aladin! I tried your formula in the summary table. But, it is fetching values only where the combination (example ABC and XYZ) being compared matches the first row and first column in any of the sheets. And, so I am getting 0 for ABC and XYZ combination.

Following is what the Summary table looks like with the formula.


Summary TableSTUTUVXYZZZZ
AAA8000
AAB0000
ABB10000
ABC9000
BCD0900
DEF0000
HIJ0000
KLM0000
MMM0000

<tbody>
</tbody>

Upon checking Evaluate formula, it looks like the array range in sheets is not being expanded to compare all the cells in range. Only the first row/column combination in sheets is being compared.

Control+shift+enter, not just enter:

=SUM(IF(T(INDIRECT("'"&Table1[SheetNames]&"'!A2:A10"))="ABC",IF(T(INDIRECT("'"&Table1[SheetNames]&"'!B1:E1"))="XYZ",N(INDIRECT("'"&Table1[SheetNames]&"'!B2:E10")))))
 
Upvote 0
Hi sunnyk
Welcome to the board

Looking at your formulas it seems to me that it's not possible to do it this way as it's like you want to work directly with a 3D array, which excel does not support.

I see 2 options:

- use vba, it would not be difficult to loop through the worksheets and do the calculations

- it case you really need (or want) to do it with a formula, I believe that you'd have to flatten the 3D array into a 2D array to perform the calculations.
It would certainly be a big formula, but I remember doing it once and it is maneageble using some named formulas.

Of course I can be wrong and I'll be happy if there's a simple direct solution. :)
 
Upvote 0
Thank you so much Aladin! I tried your formula in the summary table. But, it is fetching values only where the combination (example ABC and XYZ) being compared matches the first row and first column in any of the sheets. And, so I am getting 0 for ABC and XYZ combination.

[...]

Upon checking Evaluate formula, it looks like the array range in sheets is not being expanded to compare all the cells in range. Only the first row/column combination in sheets is being compared.

Right, quite so. I agree with what pgc01 asserts in his reply.
 
Upvote 0
Thanks so much PGC and Aladin for looking into my question!!

Given that (fortunately) I don't have to deal with too many tabs to deal with, I will use a formula to sum the 3d formulas for each sheet.

What I found strange was that that out of the two formulas in my first post: one expanded the entire cell range (but only for the first sheet) for comparison using index and match, and another looked into each of the sheets but compared only the first row/column combination (did not expand cell range). This led me to believe that there was some way Excel would allow me to reap both the benefits (looking into each of the sheets and across entire cell range for full comparison).

Just a follow-up question: For the 1st formula (using Sumproduct, Index, Indirect, Match) I did not have to use Ctrl+Shift+Enter for it to work. However, for the 2nd formula (using Sumproduct, Indirect) I had to use Ctrl+Shift+Enter for it to work. Why is former being treated as regular formula but latter being treated as Array formula?

Formula 1:
=IFERROR(SUMPRODUCT(INDEX(INDIRECT("'"&Table1[SheetNames]&"'!$B$2:$E$10"),MATCH(“ABC”,INDIRECT("'"& Table1[SheetNames]&"'!$A$2:$A$10"),0),MATCH(“XYZ”,INDIRECT("'"& Table1[SheetNames]&"'!$B$1:$E$1"),0))),)

Formula 2:
=SUMPRODUCT((T(INDIRECT("'"& Table1[SheetNames]&"'!$A$2:A10"))=”ABC”)*(T(INDIRECT("'"& Table1[SheetNames]&"'!$B$1:$E$1"))=”XYZ”),N(INDIRECT("'"& Table1[SheetNames]&"'!$B$2:$E$10")))

Thanks,
Sunny
 
Upvote 0

Forum statistics

Threads
1,215,641
Messages
6,125,986
Members
449,276
Latest member
surendra75

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