I have a transactional table that looks like data that would flow in from a point of sale. Using DAX/Power BI, I want to be able to count and sum the instances where Item A is more frequent on the invoice than Item B.
I'm having a hard time pasting my data but imagine a transactional dataset with 3 Columns: Invoice Number, Qty sold, Product
Invoice | Qty sold | Product
---------------------------------
1111 | 5 | Apples
1111 | 6 | Bananas
1111 | 6 | Oranges
1112 | 10 | Apples
1112 | 5 | Bananas
1112 | 3 | Oranges
1112 | 3 | Strawberries
And I want to be able to see it every combination of products above and how frequently 1 has a greater sales quantity than the other:
Apples > Apples: 0
Apples > Bananas: 1
Apples > Oranges: 2
Apples > Strawberries: 1
Bananas > Bananas: 0
Bananas > Apples: 1
Bananas > Oranges: 2
etc
I have tried duplicating the table and doing a many to many join on invoice. From there, count rows from table 1 where count > than table 2 using the "related" and "related table" functions (this is how I would do it in SQL). This hasn't worked due to the many to many nature. I have also tried something like this but it is not providing the desired output:
MoreFreq =
CALCULATE(
COUNT(Fact2[Qty Sold]),
FILTER(
Fact2,
Fact2[Qty Sold] > Fact1[Qty Sold]
)
)
Any help would be appreciated. Thanks!