Array Formulas

macandal

New Member
Joined
Jan 13, 2012
Messages
36
I have lists of investments categorized by years (e.g.: 2001.xls, 2002.xls, 2003.xls, etc). I need to pull certain data from those files to create the reports I need. Pivot Tables and the Consolidate function might be answer to my needs. Besides those functions, I think Array Formulas might also help me isolate the information I need. The final product, I think, would be a combination of Array Formulas, Pivot Tables, and the Consolidate function. Anyway, I wrote my first array formula but it didn't work. I hope someone here can help me.

This is my formula:

{=SUM(IF((B2:B57="Buy"),(C2:C57="XY")))*((F2:F57),(I2:I57))}

What I want it to say (or do) is that if column B says "Buy" and column C says "XY" [that's the condition], then add the amounts in columns F and I that meet that condition. (In other words, if I bought [Buy] shares in a specific company [in this case, XY], how much did I pay for them [column F, price, + column I, commission].)

Can someone please help? Thanks.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I have lists of investments categorized by years (e.g.: 2001.xls, 2002.xls, 2003.xls, etc). I need to pull certain data from those files to create the reports I need. Pivot Tables and the Consolidate function might be answer to my needs. Besides those functions, I think Array Formulas might also help me isolate the information I need. The final product, I think, would be a combination of Array Formulas, Pivot Tables, and the Consolidate function. Anyway, I wrote my first array formula but it didn't work. I hope someone here can help me.

This is my formula:

{=SUM(IF((B2:B57="Buy"),(C2:C57="XY")))*((F2:F57),(I2:I57))}

What I want it to say (or do) is that if column B says "Buy" and column C says "XY" [that's the condition], then add the amounts in columns F and I that meet that condition. (In other words, if I bought [Buy] shares in a specific company [in this case, XY], how much did I pay for them [column F, price, + column I, commission].)

Can someone please help? Thanks.
Control+shift+enter, not just enter:

=SUM(IF(B2:B57="Buy",IF(C2:C57="XY",F2:F57+I2:I57)))
 
Upvote 0
I have another issue. What if now I want to say, if column B says "Buy" or "[Whatever other code]" and column C says "XY" [that's the condition], then add the amounts in columns F and I that meet that condition. Basically I'm adding the condition highlighted in red; otherwise the formula is the same as the one provided here that worked. Thanks.
 
Upvote 0
I have another issue. What if now I want to say, if column B says "Buy" or "[Whatever other code]" and column C says "XY" [that's the condition], then add the amounts in columns F and I that meet that condition. Basically I'm adding the condition highlighted in red; otherwise the formula is the same as the one provided here that worked. Thanks.
Like this...

Array entered**:

=SUM(IF(ISNUMBER(MATCH(B2:B57,{"Buy","Hold"},0)),IF(C2:C57="XY",F2:F57+I2:I57)))

Better to use cells to hold the criteria:

A1 = Buy
B1 = Hold
C1 = XY

=SUM(IF(ISNUMBER(MATCH(B2:B57,A1:B1,0)),IF(C2:C57=C1,F2:F57+I2:I57)))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Or, this normally entered version:

=SUMPRODUCT(--ISNUMBER(MATCH(B2:B57,A1:B1,0)),--(C2:C57=C1),F2:F57+I2:I57)
 
Upvote 0
Better to use cells to hold the criteria
Can't use cells because the criteria I am using to filter the data I need is not always in the same place.

Can't I just add the other criteria (in my example, the "Or" part in red) to the formula that I already have [=SUM(IF(B2:B57="Buy",IF(C2:C57="XY",F2:F57+I2:I57)))]?
 
Upvote 0
Like this...

Array entered**:

=SUM(IF(ISNUMBER(MATCH(B2:B57,{"Buy","Hold"},0)),IF(C2:C57="XY",F2:F57+I2:I57)))

Better to use cells to hold the criteria:

A1 = Buy
B1 = Hold
C1 = XY

=SUM(IF(ISNUMBER(MATCH(B2:B57,A1:B1,0)),IF(C2:C57=C1,F2:F57+I2:I57)))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Or, this normally entered version:

=SUMPRODUCT(--ISNUMBER(MATCH(B2:B57,A1:B1,0)),--(C2:C57=C1),F2:F57+I2:I57)

Can't use cells because the criteria I am using to filter the data I need is not always in the same place.

Can't I just add the other criteria (in my example, the "Or" part in red) to the formula that I already have [=SUM(IF(B2:B57="Buy",IF(C2:C57="XY",F2:F57+I2:I57)))]?
You can also do it like this...

Still array entered:

=SUM(IF(B2:B57={"Buy","Hold"},IF(C2:C57="XY",F2:F57+I2:I57)))

...but the ISNUMBER(MATCH version is more efficient.

=SUM(IF(ISNUMBER(MATCH(B2:B57,{"Buy","Hold"},0)),IF(C2:C57="XY",F2:F57+I2:I57)))
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

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