Power BI How-To / Product Affinity

How to Run a Market Basket Analysis in Power BI

A Power BI market basket analysis finds which products land in the same order and scores every pair with three numbers: support, confidence and lift. This guide builds it from a plain order-lines table, using a disconnected second product table, a handful of DAX measures, a worked example and a noise filter. It is the do-it-yourself how-to. If you would rather have basket and attach-rate views built into a full sales, inventory and marketing report, that is part of our Power BI retail dashboard work.

The short version

Four pieces every pair matrix needs

Order lines at the right grain

One row per product per order, with a stable order ID. Header-level sales tables cannot show what was bought together, because the products are already summed away.

A second, unrelated product list

A calculated copy of the product names with no relationship to anything. It supplies the column side of the matrix, so each cell is one product paired with another.

Three ratios, not one

Support says how common a pair is, confidence says how often one product leads to the other, and lift says whether the pairing beats chance. Each one alone misleads.

A minimum-support filter

Pairs that share only a few orders produce dramatic lift values that mean nothing. A floor on shared orders keeps the matrix to pairs worth acting on.

What does a market basket analysis measure?

Market basket analysis looks at which products appear in the same order. For every pair of products it reports three numbers: support, the share of all orders containing both; confidence, the share of orders with the first product that also contain the second; and lift, which compares that confidence with how often the second product sells anyway.

The three are standard association-rule measures, and each answers a different question. Support tells you whether a pair is common enough to matter. Confidence is directional: the share of coffee-bean orders that include filters is not the same as the share of filter orders that include beans. Lift removes the effect of popularity. A best-seller shows up in a lot of baskets simply because it is in a lot of orders, and lift is the measure that corrects for that.

The three basket metrics for a pair of products A and B, with the standard formula and how to read each one.
Metric Standard formula How to read it
Support (A, B) Orders with A and B ÷ all orders How common the pair is across the whole business; the same value in both directions
Confidence (A → B) Orders with A and B ÷ orders with A Of the orders that contain A, the share that also contain B; differs by direction
Lift (A, B) Confidence (A → B) ÷ (orders with B ÷ all orders) Above 1, the pair appears together more often than chance; near 1, no association; below 1, less often than chance

What data does a basket model need?

You need order lines: one row per product per order, with an order ID and a product key. A products table related to those lines supplies the first product in each pair, and a second, disconnected copy of the product list supplies the partner product. A marked Date table is optional but useful for slicing.

Most sources can produce that grain. A Shopify line-item export, Square itemized sales and Toast item-level selections all carry an order or check ID beside each item. Clean three things before building anything. Remove refunded and voided lines, or a returned item still counts toward a pair. Decide how to treat quantity: basket analysis counts orders, so two of the same mug in one order is still one order containing a mug. And decide the product level, because size and color variants split one real product into several weak ones. The rest of the model is a normal star schema, with the order-lines table as the fact and products, dates and stores as dimensions.

How do you build the second product table?

Create a calculated table such as Product B = DISTINCT( Products[Product] ) and leave it unrelated to everything. Put Products[Product] on the rows of a matrix and 'Product B'[Product] on the columns. Because the copy has no relationship, its filter does nothing until a measure moves it onto the Products table with TREATAS.

That is the core of the pattern. The rows of the matrix filter the order lines through the normal relationship, so every measure already knows product A. The column header picks a value in 'Product B', and a measure takes that value, removes the product A filter, and applies the column value to Products[Product] instead. TREATAS is the function that applies a table of values as a filter on a column from an unrelated table; Microsoft’s TREATAS function reference (opens in new tab) documents the syntax and its DirectQuery limits. Make sure the column you copy is unique per product; if two products share a name, copy the product key and show the name through a lookup.

Which DAX measures calculate support, confidence and lift?

Four counting measures do the work. Orders counts distinct order IDs for the row product. Orders with B counts orders containing the column product. Orders with Both intersects the two order lists. Total Orders ignores the product filter. Support, confidence and lift are then simple DIVIDE calls over those counts, so blanks replace divide-by-zero errors.

The basket measures: the DAX for each and what it returns in a matrix cell (Products[Product] on rows as A, 'Product B'[Product] on columns as B).
Measure DAX What it returns in a cell
Orders DISTINCTCOUNT( Sales[OrderID] ) Orders containing product A
Orders with B CALCULATE( [Orders], REMOVEFILTERS( Products ), TREATAS( VALUES( 'Product B'[Product] ), Products[Product] ) ) Orders containing product B
Orders with Both VAR OrdersA = VALUES( Sales[OrderID] ) VAR OrdersB = CALCULATE( VALUES( Sales[OrderID] ), REMOVEFILTERS( Products ), TREATAS( VALUES( 'Product B'[Product] ), Products[Product] ) ) RETURN COUNTROWS( INTERSECT( OrdersA, OrdersB ) ) Orders containing both A and B
Total Orders CALCULATE( [Orders], REMOVEFILTERS( Products ) ) All orders in the current date and store context
Support DIVIDE( [Orders with Both], [Total Orders] ) Share of all orders that contain the pair
Confidence DIVIDE( [Orders with Both], [Orders] ) Share of A orders that also contain B
Lift DIVIDE( [Confidence], DIVIDE( [Orders with B], [Total Orders] ) ) Confidence relative to how often B sells on its own

Write Orders with Both across several lines in the editor; it is shown on one line here only to fit the table. Two details keep it honest. First, the diagonal: a product paired with itself returns its own order count and a meaningless lift, so wrap the measure in IF( SELECTEDVALUE( Products[Product] ) = SELECTEDVALUE( 'Product B'[Product] ), BLANK(), … ). Second, REMOVEFILTERS on Products also clears any category slicer for the partner side, which is usually what you want: “of orders with this jacket, how many also had any given accessory”. Date and store filters pass straight through, so the same matrix answers the question for one season or one location. Microsoft’s CALCULATE function reference (opens in new tab) explains how those filter arguments replace and keep context.

How do you read a worked market basket example?

Below is illustrative sample data for a small coffee retailer with 1,000 orders. Read lift first: above 1 means the pair sells together more often than chance, near 1 means no association, below 1 means they appear together less often than chance. Then check support, because a high lift on a handful of orders is noise.

Illustrative sample data, not client results: 1,000 orders, of which 200 contain coffee beans, 80 contain paper filters and 150 contain mugs.
Pair (A → B) Orders with both Support Confidence Lift Reading
Beans → Filters 60 6% 30% (60 ÷ 200) 3.75 Strong pairing; filters sell far more often alongside beans than on average
Filters → Beans 60 6% 75% (60 ÷ 80) 3.75 Same pair, other direction: most filter buyers also take beans
Beans → Mugs 30 3% 15% (30 ÷ 200) 1.00 No association; mugs sell to bean buyers at the same rate as to everyone
Filters → Mugs 6 0.6% 7.5% (6 ÷ 80) 0.50 Below chance, and on too few orders to act on

Three lessons sit in those four rows. Support and lift are symmetric, so Beans → Filters and Filters → Beans share them, while confidence is not: 75% of filter orders include beans, but only 30% of bean orders include filters. That asymmetry tells you where a cross-sell prompt belongs, on the filter page suggesting beans rather than the reverse. Beans → Mugs looks respectable at 30 shared orders, but a lift of 1.00 says mugs would have sold to those customers anyway, so a bundle would mostly discount sales you already had. And Filters → Mugs shows why support comes before lift: six orders is not a pattern.

How do you keep the pair matrix from turning into noise?

Set a minimum support before anyone reads lift. Add a visual-level filter that keeps only pairs above a minimum number of shared orders, hide the diagonal where a product is paired with itself, and sort by lift within what remains. The right threshold depends on your order volume, so agree it with the merchandising team.

A full product-by-product matrix is rarely the best final visual. Most teams get more from a table visual with one row per pair: product A, product B, orders with both, support, confidence and lift, filtered to the minimum and sorted by lift or confidence. Add a slicer on product A so a buyer can pick one item and see its strongest partners. Keep the matrix with a background color scale on lift for exploring a single category. Apply the same floor to every measure through the visual filter rather than inside each measure, so the rule is visible and easy to change.

How do product pairs become bundles and cross-sells?

Use the three numbers together. High confidence from A to B suggests recommending B on A’s product page or at checkout. High lift with healthy support suggests a bundle or shelf adjacency. Low support with high lift is a test candidate, not a decision. Measure any change against a baseline period before calling it a win.

  • Cross-sell prompts: rank partners for each product by confidence, filtered to a lift above 1, and use the top few as “often bought with” suggestions.
  • Bundles: look for pairs with both healthy support and clear lift. Support near the top but lift near 1 means the products are simply both popular, and a bundle discount would mostly give margin away.
  • Placement: in a physical store, category-level pairs with strong lift are candidates for adjacency; in a restaurant, they suggest menu pairings and server prompts.
  • Follow-up: after a change, compare attach rate and average order value against a comparable earlier period on the same report, so the result is measured rather than assumed.

Basket analysis relates products to each other. If the question is how customers behave over time instead, such as how many first-time buyers return, that is a different model, covered in our guide to Power BI cohort analysis for customer retention.

When does basket analysis outgrow a DAX measure?

When the product list runs into the thousands, the pair matrix grows with the square of the product count and every cell runs an order-list intersection. At that point, precompute a pairs table upstream in Power Query, SQL or a Fabric notebook, and let DAX only sum and divide the stored counts.

The upstream version is a self-join of the order lines on order ID, keeping rows where product A sorts before product B so each pair appears once, then grouped to one row per pair with a count of distinct orders. Store per-product order counts and the total order count beside it, and support, confidence and lift become cheap divisions. The trade-off is flexibility: a precomputed table only slices by the columns you kept in it, so add date and store keys if those slicers matter. For a store on Shopify, that build sits alongside the sales, margin and repeat-purchase views in a Shopify Power BI dashboard.

When should a senior engineer build it for you?

Bring in help when the basket results will drive pricing, bundles or store layout and the order data is messy: several sales channels, kits and modifiers on separate lines, refunds, or product IDs that changed between systems. The DAX here is short; agreeing the product grain and cleaning the order lines is where most of the work sits.

Power BI Flex Support is prepaid, senior-led Power BI hours that never expire, with no contracts and no project minimums. Blocks are Starter $2,500, Growth $4,600 and Power $8,000, and hourly work starts from $100. You send the request, we reply with a scope and an hours estimate before any work, hours are deducted only for work you approve, and most tasks land 3–5 business days after approval. If the basket measures are slow because the model underneath is tangled, the same hours cover data modeling and DAX work. Contact is through the form on this site.

FAQ

Frequently asked questions

No. Market basket analysis describes what has sold together in past orders, using simple counts and ratios. A recommendation engine predicts what one shopper is likely to want next, often from browsing history and machine learning. Basket results are a good starting point for manual cross-sell rules and a useful baseline for judging any engine.

Start one level above the SKU. Size and color variants of the same item split the counts and hide real pairs, so most teams group to product or style first and drop to SKU only for a shortlist. Category pairs answer store layout questions; product pairs answer bundle and cross-sell questions.

Yes. A restaurant check is a basket, and the pairs show which items, sides or drinks are ordered together. The main extra step is handling modifiers, which many POS exports store as separate lines. Decide whether a modifier counts as its own product or rolls up to the menu item before building the pair matrix.

You can, with a Python visual or a Power Query Python step that calls an association rules library. A Power Query Python step needs a personal gateway for scheduled refresh, so for pair-level support, confidence and lift the DAX pattern is usually simpler to maintain. Python earns its place for rules that combine three or more items.

Yes. A senior, US-based, Microsoft-certified engineer can build the pair model and measures on your own order lines from prepaid Flex hours that never expire. Blocks are Starter $2,500, Growth $4,600 and Power $8,000, with hourly work from $100. We quote the hours before starting, and most tasks land in 3 to 5 business days after approval.

Try us risk-free for 4 hours

If you’re unhappy within the first 4 hours of your block, we’ll refund you in full — no questions asked. Hours are deducted only for work you’ve reviewed and approved, and they never expire.

Want product pairs your buyers can act on?

Bring your order-line data to a free demo. We agree the product grain with you, clean the lines and build the support, confidence and lift views on prepaid hours that never expire. Most tasks land in 3–5 business days.

Scope approved before any hours are used · Hours never expire

Book a free demo

See what your Power BI reporting would take

Tell us the task. We reply within one business day, and you get a scope estimate and the hours needed before any work begins.

Step 1 of 2: What do you need?

How can we help? Pick one

Tap to add, or type your own:

Step 2 of 2: Where should we reply?

Used only to contact you about this inquiry.

We reply within one business day. Scope approved before any hours are used. We don’t sell your information.

Tell us the task. We scope it, you approve, and a senior consultant delivers — typically in 3–5 business days. Prepaid hours that never expire.

  • Prepaid hours from $100/hour — and they never expire
  • Senior-led delivery — 20+ years on the Microsoft platform
  • Typical 3–5 business day turnaround
  • Full refund if you’re unhappy in your first 4 hours
Book my free demo