Is this Possible?

MikeDBMan

Well-known Member
Joined
Nov 10, 2010
Messages
610
Is it possible to embed an if-then-else statement into a sumproduct function? For example: will this work:

=Sumproduct((table1[Location]=$A$1)*(table1[ProductType]=$A$2)*(if(table1[Period]="Qtr1",1,0))*(table1[extension]))

I have tried it and it just basically "ignores" the period parameters. Any ideas on a work-around. One I thought of is to have different columns in my table for the Q1 amounts, Q2 amounts, etc and then pull from the different Extension columns to get the right stuff. But I was hoping to avoid that extra overhead. Ideas?
 
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
This should work

=Sumproduct((table1[Location]=$A$1)*(table1[ProductType]=$A$2)*(table1[Period]="Qtr1")*(table1[extension]))
 
Upvote 0
Yes, you are correct. Now I am remembering, the real problem was sometimes I want to include all data regardless of the period and sometimes just one period. In other words, if A3 has "All" in it, then I'd want to pick up all the data. If it has Q1 in it I want to pick up only the Q1 data. Suggestions on how to do that? So my if statement might be:

(if($a$3="All",1,table1[Period]=$a$3)

That does not seem to work.
 
Upvote 0
Yes, you are correct. Now I am remembering, the real problem was sometimes I want to include all data regardless of the period and sometimes just one period. In other words, if A3 has "All" in it, then I'd want to pick up all the data. If it has Q1 in it I want to pick up only the Q1 data. Suggestions on how to do that? So my if statement might be:

(if($a$3="All",1,table1[Period]=$a$3)

That does not seem to work.

Try...
Code:
=SUMPRODUCT(
    (table1[Location]=$A$1)*
    (table1[ProductType]=$A$2)*
    (table1[Period]=IF(A3="All",table1[Period],A3))*
    (table1[extension]))

Or slightly better:
Code:
=SUMPRODUCT(
    --(table1[Location]=$A$1),
    --(table1[ProductType]=$A$2),
    --(table1[Period]=IF(A3="All",table1[Period],A3)),
    (table1[extension]))
 
Upvote 0
Aladin,
your method worked! Thanks so much. I was writing the If-then-else basically backwards. But yours works perfectly!
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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