count invoices with multiple AND filters

MrAnderson

New Member
Joined
Mar 6, 2014
Messages
6
Hi,

I’m trying to count the number of instances where a customer has bought 2 particular products in the same invoice. Let’s assume I have the following table called "invoices.


ABCDE
InvoiceIdInvoiceDateProductIDPriceProductName
a
b
a
d
a
b
e

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]01/01/2012[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]100[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]01/01/2012[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]50[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]02/02/2012[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]100[/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]02/02/2012[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]25[/TD]

[TD="align: center"]6[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]03/03/2012[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]100[/TD]

[TD="align: center"]7[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]03/03/2012[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]50[/TD]

[TD="align: center"]8[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]03/03/2012[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]25[/TD]

</tbody>
Facturas



The result I want is the following

HI
Jan
Feb
March

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]2[/TD]

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

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

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

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

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

</tbody>
Facturas



I have tried with the CALCULATE function with these formulae:
=calculate(distinctcount(Invoices[InvoiceId],Invoices[ProdId]=1;Invoices[ProdId]=2)
Or
=calculate(distinctcount(Invoices[InvoiceId],Invoices[ProdId]=1&&Invoices[ProdId]=2)

but I get no results, can anyone give a hand?

thanks a lot!.
 
CALCULATE can take any number of filter params. You currently have one which is "which invoices do we even consider?". Now you want to add another which is "Only include Products 1 or 2".

That reads okay, and maybe it is correct!?

FILTER(ALL(Invoices[ProductId]), Invoices[ProductId] = 1 || Invoices[ProductId] = 2)

(This would be your 3rd param to the outer calculate)
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Sweet, that's how you can do it. Didn't think of that. I was thinking putting the logic into one filter expression
 
Upvote 0

Forum statistics

Threads
1,224,041
Messages
6,176,027
Members
452,697
Latest member
CuriousSpreadsheet

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