Q:

How to count orders with condition A and B in dax

I have a table with order number and product code. One order can have multiple lines. I would like to count the number of orders which have BOTH product code A AND product code B.
My table looks like this:
OrderNumber ProductCode
Order1      A
Order1      B
Order2      B
Order3      A
Order3      B
Order4      C
So for this result set, the answer would be 2, as both Order1 and Order3 contains both A and B.
I would very much like to create this as a measure in dax.
Thank you.

A:

Try this:
SUMX(
  CALCULATETABLE(
   VALUES(MyTable[OrderNumber]), 
   MyTable[ProductCode] = "A"
  ),
  IF(CALCULATE(COUNTROWS(MyTable),MyTable[ProductCode] = "B") > 0,1)
)

