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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,225,375
Messages
6,184,613
Members
453,247
Latest member
scouterjames

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