SUMIF or SUMPRODUCT

adrienne0914

Board Regular
Joined
Mar 22, 2018
Messages
73
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I am trying to figure out the best formula for this problem. My workbook is more complicated, but in a nutshell here is what I'm trying to create a formula for:

Data Tab
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ANIMAL[/TD]
[TD]COUNT[/TD]
[/TR]
[TR]
[TD]Cats[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]Dogs[/TD]
[TD]245[/TD]
[/TR]
[TR]
[TD]Rabbits[/TD]
[TD]17[/TD]
[/TR]
</tbody>[/TABLE]


Animals tab
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Cats[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]Dogs[/TD]
[TD]N[/TD]
[/TR]
[TR]
[TD]Bears[/TD]
[TD]Y[/TD]
[/TR]
</tbody>[/TABLE]

Month tab
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Jan[/TD]
[TD]y[/TD]
[/TR]
[TR]
[TD]Feb[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]Mar[/TD]
[TD]N[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]CM1[/TD]
[TD]CM2[/TD]
[/TR]
[TR]
[TD]Cats[/TD]
[TD]50[/TD]
[TD]75[/TD]
[/TR]
[TR]
[TD]Dogs[/TD]
[TD]42[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]Bears[/TD]
[TD]22[/TD]
[TD]37[/TD]
[/TR]
</tbody>[/TABLE]

If animal=Y and month=Y, multiply COUNT by CM1, otherwise multiply COUNT by CM2. So for instance, both conditions are met by cat. So multiply 18*50.

I hope someone can help.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,

I have used combination of IF and VLOOKUP to get to this, and for Month I have used today's date (=TODAY()) if you want you can change that with any particular month or refer to a cell where month is given. Just to see whether this works I had kept everything on the same tab. See if it fulfills your requirement:

ABCDEFGHIJKLMNOPQ
AnswerJuny
FebY
MarN

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]ANIMAL[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]COUNT[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Cats[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Y[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]CM1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]CM2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Cats[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]18[/TD]
[TD="align: right"]900[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Dogs[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]N[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Cats[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]50[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]75[/TD]

[TD="align: center"]3[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Dogs[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]245[/TD]
[TD="align: right"]4410[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Rabbits[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Y[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Dogs[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]42[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]18[/TD]

[TD="align: center"]4[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Rabbits[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]17[/TD]
[TD="align: right"]374[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Rabbits[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]22[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]37[/TD]

</tbody>
Sheet5

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]C2[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A2,$F$1:$G$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),$K$1:$L$3,2,FALSE)="Y"),B2*VLOOKUP(A2,$O$2:$Q$4,2,FALSE),B2*VLOOKUP(A2,$O$2:$Q$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]C3[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A3,$F$1:$G$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),$K$1:$L$3,2,FALSE)="Y"),B3*VLOOKUP(A3,$O$2:$Q$4,2,FALSE),B3*VLOOKUP(A3,$O$2:$Q$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]C4[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A4,$F$1:$G$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),$K$1:$L$3,2,FALSE)="Y"),B4*VLOOKUP(A4,$O$2:$Q$4,2,FALSE),B4*VLOOKUP(A4,$O$2:$Q$4,3,FALSE))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Thanks for the replay, Aryatect. I think this will work, but I'm having problems translating to multiple tabs with my file setup. I'll let you know if it works.

ABCDEFGHIJKLMNOPQ
ANIMALCOUNTAnswerCatsYJunyCM1CM2
CatsDogsNFebYCats
DogsRabbitsYMarNDogs
RabbitsRabbits

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]18[/TD]
[TD="align: right"]900[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]50[/TD]
[TD="align: right"]75[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]245[/TD]
[TD="align: right"]4410[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]42[/TD]
[TD="align: right"]18[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]17[/TD]
[TD="align: right"]374[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]22[/TD]
[TD="align: right"]37[/TD]

</tbody>
Sheet5

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]C2[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A2,$F$1:$G$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),$K$1:$L$3,2,FALSE)="Y"),B2*VLOOKUP(A2,$O$2:$Q$4,2,FALSE),B2*VLOOKUP(A2,$O$2:$Q$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH]C3[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A3,$F$1:$G$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),$K$1:$L$3,2,FALSE)="Y"),B3*VLOOKUP(A3,$O$2:$Q$4,2,FALSE),B3*VLOOKUP(A3,$O$2:$Q$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH]C4[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A4,$F$1:$G$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),$K$1:$L$3,2,FALSE)="Y"),B4*VLOOKUP(A4,$O$2:$Q$4,2,FALSE),B4*VLOOKUP(A4,$O$2:$Q$4,3,FALSE))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
I have moved the data as per your tabs named Data, Animals, Months & CM tab (there was no name so just adding this) then the final formula will look like below:

ABC
ANIMALCOUNTAnswer
Cats
Dogs
Rabbits

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]18[/TD]
[TD="align: right"]900[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]245[/TD]
[TD="align: right"]4410[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]17[/TD]
[TD="align: right"]374[/TD]

</tbody>
Data

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]C2[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A2,Animals!$A$1:$B$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),Months!$A$1:$B$3,2,FALSE)="Y"),B2*VLOOKUP(A2,'CM Tab'!$A$2:$C$4,2,FALSE),B2*VLOOKUP(A2,'CM Tab'!$A$2:$C$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH]C3[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A3,Animals!$A$1:$B$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),Months!$A$1:$B$3,2,FALSE)="Y"),B3*VLOOKUP(A3,'CM Tab'!$A$2:$C$4,2,FALSE),B3*VLOOKUP(A3,'CM Tab'!$A$2:$C$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH]C4[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A4,Animals!$A$1:$B$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),Months!$A$1:$B$3,2,FALSE)="Y"),B4*VLOOKUP(A4,'CM Tab'!$A$2:$C$4,2,FALSE),B4*VLOOKUP(A4,'CM Tab'!$A$2:$C$4,3,FALSE))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

Happy to Help !!
 
Last edited:
Upvote 0
Thanks! I was able to work out the first part of the formula. My issue is with the B2. In my workbook, it won't be looking at a single cell. It will have to search a column on another tab (say Data) for a match, then go to the 'CM Tab' other part of the multiplication. Would that be another VLOOKUP?

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]C2[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A2,Animals!$A$1:$B$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),Months!$A$1:$B$3,2,FALSE)="Y"),B2*VLOOKUP(A2,'CM Tab'!$A$2:$C$4,2,FALSE),B2*VLOOKUP(A2,'CM Tab'!$A$2:$C$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH]C3[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A3,Animals!$A$1:$B$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),Months!$A$1:$B$3,2,FALSE)="Y"),B3*VLOOKUP(A3,'CM Tab'!$A$2:$C$4,2,FALSE),B3*VLOOKUP(A3,'CM Tab'!$A$2:$C$4,3,FALSE))[/TD]
[/TR]
[TR]
[TH]C4[/TH]
[TD="align: left"]=IF(AND(VLOOKUP(A4,Animals!$A$1:$B$3,2,FALSE)="Y",VLOOKUP(TEXT(TODAY(),"mmm"),Months!$A$1:$B$3,2,FALSE)="Y"),B4*VLOOKUP(A4,'CM Tab'!$A$2:$C$4,2,FALSE),B4*VLOOKUP(A4,'CM Tab'!$A$2:$C$4,3,FALSE))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

Happy to Help !!
 
Upvote 0
Yes, you are right, that here I had used B2 as there was a single value there in the same table, if it is coming from some other tab, then B2 will be replaced by another VLOOKUP to get that value which will be used for calculation.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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