Let sales filter products with CROSSFILTER BOTH

Make the Sales table filter Product for one calculation with CROSSFILTER BOTH, and find the average list price of the products each customer bought.

You will learn to

  • Make a relationship filter in both directions inside CALCULATE
  • Aggregate a dimension column for the items a customer bought
  • Tell a per-product average from a per-order-line average

How it works

Filters normally flow one way: from Product **to** Sales. In a customer’s row, Sales is filtered to that customer, but Product is untouched, so `AVERAGE(Product[Price])` is the average of all twelve products for everyone.

`CROSSFILTER(Sales[ProductKey], Product[ProductKey], BOTH)` inside CALCULATE makes that one relationship work in both directions. Now the visible Sales rows filter Product too: Product shows only the products this customer bought.

That is different from averaging the price over sales rows. A product bought ten times counts ten times in `AVERAGEX(Sales, RELATED(Product[Price]))`, but only once after CROSSFILTER, because you are averaging over **products**. Use BOTH sparingly, inside one measure, rather than setting a model relationship to both directions.

Practice it hands-on with a real data model and a live report that updates as you type.

Colors Bought = CALCULATE(DISTINCTCOUNT(Product[Color]), CROSSFILTER(Sales[ProductKey], Product[ProductKey], BOTH))