CountX or something more?

one3nine0

Board Regular
Joined
Jul 21, 2014
Messages
127
I have a table of sales data which includes invoice number, item number, quantity, and $ amount.

I want to show the count of the number of times two products appear in the same invoice.

For instance, when I create a pivot table, i want to have a measure that will show the count of number of times Item A and B in the same invoice. From the table below, Invoice 2, 3, and 4 would show a count of 1 (each invoice had product A and B) in it, and invoice 1 would have 0.

Invoice #ItemQuantity$ Amount
1A1$400
1C1$200
2A1$400
2B2$500
3A1$400
3B1$250
4A2$800
4B4$1000
4C6$1200

<tbody>
</tbody>

For bonus points: the main goal is to identify which invoices have items A and B in it, and then swap out item B for another item and price to find out new invoice total. The idea is to find out what the total selling point would be if one item was upgraded to another, and to be able to visually see that in a pivot table comparison
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi there,

Your first question can be answered with a "Basket Analysis" pattern. See here on DAX Patterns.

You basically add a 'Filter Item' table to your data model with an inactive relationship to your Sales table, and set up a measure that looks like this:
Code:
=
CALCULATE (
    DISTINCTCOUNT ( Sales[Invoice #] ),
    CALCULATETABLE (
        SUMMARIZE ( Sales, Sales[Invoice #] ),
        ALL ( Sales[Item] ),
        USERELATIONSHIP ( Sales[Item], 'Filter Item'[Filter Item] )
    )
)

Sample PowerPivot model using your data here.

On your second question, I'm sure that can be done somehow, but would need to understand the full logic about which item is replaced with which to offer any suggestions.

Best regards,
Owen
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,664
Members
449,045
Latest member
Marcus05

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