Which products are bought together, and why it matters
If you manage a shop, an online store or a category in a supermarket chain, you make cross-selling decisions every week, often by gut feeling. Which product goes next to the coffee? Which item should the checkout page suggest? Which two products are worth a bundle discount, and which bundle would only give away margin on things customers buy together anyway? Market basket analysis answers these questions from data you already have: the receipts.
The method is simple at its core. You look at many shopping baskets and count how often items appear, alone and together. From those counts come three famous measures: support (how common is an item or a pair?), confidence (if a customer buys A, how often do they also buy B?) and lift (is that more often than chance?). Recommendation engines, “frequently bought together” boxes and planogram decisions are all built on this logic, and you can do the whole analysis in Excel without any add-in.
This free first lesson covers the foundation everything else rests on: getting baskets into the right shape, counting item frequency and calculating support. We use the same fictional shop as the lab above, Fennel & Fig Grocery, a neighbourhood store, and its 24 baskets from a Saturday morning. All numbers are illustrative.

The core idea: one row per basket, one 0/1 column per item
Point-of-sale systems usually export order lines: one row per item sold, with a receipt number. For basket analysis you need a different shape, often called a one-hot or binary basket table: one row per basket (transaction) and one column per item, with 1 if the item is in the basket and 0 if not. Quantity does not matter: a basket with three bananas and a basket with one banana both get a 1 in the Bananas column, because the question is “was it bought together?”, not “how much?”.
The 0/1 shape makes everything else easy. Counting the baskets that contain bread is just adding up the bread column, because every 1 is a basket with bread and every 0 adds nothing. Counting baskets that contain bread and butter means multiplying the two columns row by row (1 × 1 = 1, anything with a 0 gives 0) and adding the products, which is exactly what SUMPRODUCT does in lesson 2.
The support of an item is the share of baskets that contain it:
support(A) = baskets containing A ÷ total number of baskets
Two details trip people up. First, support is a share of baskets, not a share of items sold. You divide by the number of baskets (24), not by the total of all 1s in the table (65). Second, support is not a measure of revenue or popularity in money terms. A cheap item in many baskets has high support, an expensive item in a few baskets has low support. Basket analysis is about co-occurrence, and you add prices later, as lab 8 of the course does.
Worked example: Fennel & Fig’s Saturday morning
The lab sheet holds 24 baskets (rows 11 to 34) and seven items in columns B to H: Bread, Butter, Milk, Coffee, Tea, Cookies and Bananas. Row 4 counts the baskets with each item, row 5 turns the counts into support, B7 counts the baskets and B8 gives the average basket size. Here are the results and the formulas that produce them:
| Item | Column | Baskets with item (row 4) | Formula | Support (row 5) | Formula |
|---|---|---|---|---|---|
| Bread | B | 11 | =SUM(B11:B34) | 45.8% | =B4/$B$7 |
| Butter | C | 7 | =SUM(C11:C34) | 29.2% | =C4/$B$7 |
| Milk | D | 15 | =SUM(D11:D34) | 62.5% | =D4/$B$7 |
| Coffee | E | 9 | =SUM(E11:E34) | 37.5% | =E4/$B$7 |
| Tea | F | 6 | =SUM(F11:F34) | 25.0% | =F4/$B$7 |
| Cookies | G | 7 | =SUM(G11:G34) | 29.2% | =G4/$B$7 |
| Bananas | H | 10 | =SUM(H11:H34) | 41.7% | =H4/$B$7 |
| Baskets in sample | B7 | 24 | =COUNTA(A11:A34) | ||
| Avg items per basket | B8 | 2.71 | =SUM(B11:H34)/B7 |
Milk is the most common item: 15 of 24 baskets, a support of 62.5%. Tea is the least common at 25.0% (6 baskets). The average basket holds 65 ÷ 24 = 2.71 different items, which fits a quick Saturday top-up shop rather than a weekly family shop. If the same calculation on a large weekly-shop dataset gave you 2.7, you would suspect that the export split receipts or dropped lines.
Why does this ranking matter before you look at a single pair? Because very common items show up in many pairs just by being common. With milk in 62.5% of baskets, you would expect milk to appear alongside almost anything about 6 times in 10, even if no customer ever thinks “milk goes with this.” Rare items have the opposite problem: a rule built on Tea rests on just 6 baskets, and one unusual customer can make it look strong. Support is the number that keeps both effects in view.
A first look at pairs: from counts to rules
Lesson 1 stops at single items, but it helps to see where the course goes next. Counting pairs gives a co-occurrence matrix: the cell in the Bread row and the Butter column holds the number of baskets containing both. In Excel it is =SUMPRODUCT(B11:B34,C11:C34), or =COUNTIFS(B11:B34,1,C11:C34,1).
From these counts come the rule measures you will build in lessons 3 to 5. Confidence of A → B is the pair count divided by the count of A. Lift divides confidence by the support of B, so it compares the rule with what chance alone would give. A lift above 1 means “bought together more often than chance”, around 1 means “no relation”, below 1 means “rarely together”. The table below previews a few rules from the same 24 baskets. Treat them as an illustration: with so few baskets, one or two receipts can move every number.
| Rule A → B | Baskets with A and B | Support(A and B) | Confidence | Lift | Reading |
|---|---|---|---|---|---|
| Butter → Bread | 6 | 25.0% | 85.7% | 1.87 | strong complement |
| Bread → Butter | 6 | 25.0% | 54.5% | 1.87 | same pair, other direction |
| Coffee → Cookies | 5 | 20.8% | 55.6% | 1.90 | strong complement |
| Milk → Bread | 7 | 29.2% | 46.7% | 1.02 | about chance |
| Milk → Bananas | 6 | 25.0% | 40.0% | 0.96 | about chance |
| Tea → Butter | 0 | 0.0% | 0.0% | 0.00 | never together |
Two lessons from this small table. First, direction matters: 85.7% of butter baskets contain bread, but only 54.5% of bread baskets contain butter, because bread is much more common. Second, a high-looking confidence can be meaningless. Milk → Bread has a confidence of 46.7%, close to bread’s own support of 45.8%, so the lift is about 1.02: milk buyers take bread no more often than anybody else. Coffee → Cookies, at a lift of 1.90, is the kind of rule worth testing in a shelf placement or a checkout suggestion.
Three decisions to make before you count anything
The formulas are easy. The judgement calls around them decide whether the results mean anything. Before you build the basket table for your own shop, settle these three questions and write the answers next to the table, so anyone reading the analysis knows what the numbers describe.
- What counts as one basket? Usually one receipt or one online order. But a customer who pays for coffee first and then comes back for a sandwich creates two receipts for one visit, and a family that splits a weekly shop across two tills creates two baskets for one shopping trip. Pick one definition and keep it, and treat returns and voided receipts consistently, usually by removing them.
- Which level of item detail? “Bread” as a category behaves very differently from “Sourdough loaf 800 g”. Categories give stable counts and broad patterns, individual products give precise recommendations but need far more baskets. A common approach is to start at category level, find the interesting pairs, then drill down only inside those categories.
- Which period and which baskets belong together? Saturday morning, weekday lunchtimes and online orders can have completely different patterns. Mixing them blurs every rule. Analyse comparable baskets together, and use a period long enough to give each item a reasonable count but short enough that the range and prices did not change much in between.
None of these choices has a single correct answer, which is why they belong in writing. The Fennel & Fig lab uses the simplest version of each: one receipt is one basket, seven broad categories, and one Saturday morning. That is ideal for learning the mechanics, and too small for real decisions: with 24 baskets, a single unusual customer can move a support value by more than four percentage points, because one basket is 1 ÷ 24 = 4.2% of the sample.
How to do it in Excel, step by step
The following steps work in any recent version of Excel and in Google Sheets. If your data is already a 0/1 table, skip to step 4.
- Export the order lines from your till or shop system: at least a receipt or order ID and a product name or category. Use categories (Bread, Coffee) rather than individual SKUs at first, otherwise every pair is rare.
- Select the data and choose Insert › PivotTable. Put the order ID in Rows, the product in Columns and the product again in Values as Count.
- Copy the PivotTable and paste it as values (Ctrl+Alt+V › Values). Replace counts above 1 with 1 and empty cells with 0, for example with a helper table using
=IF(B11>0,1,0). In Excel 365 you can also do it in Power Query with Data › From Table/Range, then Transform › Pivot Column. - Arrange the table like the lab: basket IDs in column A from row 11, item names in the header row, 0/1 values in the grid.
- In
B7count the baskets:=COUNTA(A11:A34). - In
B4type=SUM(B11:B34), selectB4:H4and press Ctrl+R to fill right. Each cell now holds the number of baskets with that item. - In
B5type=B4/$B$7(press F4 on B7 to add the dollar signs), fill right with Ctrl+R and format as a percentage with Ctrl+Shift+%. - In
B8calculate the average basket size:=SUM(B11:H34)/B7. - Sanity-check: every support value must be between 0% and 100%, the counts in row 4 must add up to the total of all 1s, and the average basket size should look plausible for the type of shop.
- Optional: select the supports and choose Insert › Charts › Clustered Column, then sort the items by support (Data › Sort on a transposed copy) for a chart like the one above.
=AVERAGE(B11:B34) gives the same 45.8% as =B4/$B$7 in one step. Keeping the count in its own row is still useful, because later lessons reuse the counts directly.Common mistakes and how to spot them
- Dividing by all items instead of all baskets. Using the total of 1s (65) gives supports that add up to 100% and look neat, but they answer a different question. Spot it: your supports sum to exactly 100%. Real supports usually sum to more, because baskets hold several items.
- Counting quantities instead of presence. A basket with 4 bananas must count as 1, not 4. Spot it: values larger than 1 in the grid, or a support above 100%.
- One row per order line instead of per basket. If each item sold has its own row, SUM counts lines, not baskets. Spot it: the number of rows is much larger than the number of distinct receipt IDs.
- Too fine a level of detail. Working with 3,000 individual products makes nearly every pair rare and every rule fragile. Spot it: most items have a support below 1%. Group them into categories first.
- Missing absolute reference.
=B4/B7filled right becomes=C4/C7, dividing by an empty cell. Spot it: #DIV/0! errors from the second item onwards. - Mixing days, stores or channels without noticing. A Saturday morning top-up shop and a Tuesday online order behave differently. Spot it: the average basket size jumps when you add more data. Analyse comparable baskets together.
Quick reference: functions and shortcuts used
| Function or shortcut | What it does here | Example |
|---|---|---|
| SUM | Counts baskets with an item, because the column holds only 0 and 1 | =SUM(B11:B34) |
| COUNTA | Counts the baskets (non-empty basket IDs) | =COUNTA(A11:A34) |
| AVERAGE | Support in one step: the mean of a 0/1 column is the share of 1s | =AVERAGE(B11:B34) |
| SUMPRODUCT | Counts baskets with two items at once (lesson 2) | =SUMPRODUCT(B11:B34,C11:C34) |
| COUNTIFS | The same pair count with conditions | =COUNTIFS(B11:B34,1,C11:C34,1) |
| $ absolute reference (F4 key) | Locks the basket count when the support formula is filled right | =B4/$B$7 |
| Ctrl+R | Fills the formula in the left cell across the selected row | Select B4:H4, press Ctrl+R |
| Ctrl+Shift+% | Formats support values as percentages | Select B5:H5 |
| Insert › PivotTable | Turns a long list of order lines into a basket-by-item 0/1 table | Rows: order ID, Columns: item |
Real-world uses
- Store layout and shelf placement: place strong complements (high lift, decent support) close together, or deliberately apart so customers pass more shelves on the way.
- “Frequently bought together” in e-commerce: rank candidate recommendations by lift and confidence, not by raw popularity, so you do not just recommend milk to everyone.
- Bundles and promotions: avoid discounting a pair that is already bought together all the time, and test bundles on pairs with high lift but modest support, where there is room to grow.
- Restaurants and cafés: find which side dishes or drinks go with which mains, and design menu combos around real ordering behaviour.
- Beyond retail: the same counts work for courses taken together, insurance products held by the same customer, or symptoms recorded on the same visit.
What you will build in the rest of this course
This first lesson is free. The lessons below make up the full course, unlocked with a one-time payment of $9.90. Each comes with its own interactive lab and instant feedback.
Pair Support with SUMPRODUCT: the Co-Occurrence Matrix. You count baskets with two items at once and fill the entire item-by-item matrix with a single formula, the table behind the heat map above.
Confidence A → B: How Often B Follows A. You look up item and pair counts with INDEX and MATCH, calculate the confidence of eight rules and see in numbers why Bread → Butter and Butter → Bread are different rules.
Lift: Is the Rule Better than Chance?. You compute support, confidence and lift for ten rules from a month of baskets and label each one as a complement, independent or substitute.
Leverage and Conviction: Size and Direction of a Rule. You add two measures that the basic trio misses: how many extra baskets a rule really accounts for, and how strongly it depends on its direction.
Filtering Rules by Minimum Support and Confidence, Ranking by Lift. You apply thresholds to 14 candidate rules, rank the survivors and discover why the rule with the biggest lift can be the one you should not trust.
The Apriori Idea: Pruning 3-Item Sets Before You Count Them. You use frequent pairs to prune candidate three-item sets the way the Apriori algorithm does, which is how basket analysis scales to large shops.
From Rules to Cross-Selling: Expected Uplift per Recommendation. You turn rules into a cross-selling plan with units, value after a coupon and a ranking of which recommendation to roll out first.
Summary
Market basket analysis starts with a 0/1 table: one row per basket, one column per item. With that shape, counting is adding: SUM gives the baskets with an item, COUNTA gives the number of baskets, and their ratio is the item’s support. At Fennel & Fig, milk is in 62.5% of the 24 baskets, tea in 25%, and the average basket holds 2.71 items. Those supports are the yardstick for every rule you will judge later, because a rule is only interesting if it beats what the supports alone would predict.
Now scroll back up to the lab and count the items, the baskets and the supports yourself. The Coach checks each cell and tells you exactly what went wrong if a formula is off. It takes about 12 minutes.
Frequently asked questions
What is support in market basket analysis?
Support is the share of all baskets that contain an item or a set of items. For example, if 11 of 24 baskets contain bread, the support of bread is 11 ÷ 24 = 45.8%.
Can I do market basket analysis in Excel without add-ins?
Yes. With a 0/1 table of baskets and items, SUM, COUNTA and SUMPRODUCT are enough for support, confidence and lift. Add-ins or Python only become necessary for very large numbers of items.
What is the difference between support, confidence and lift?
Support measures how common an item or pair is. Confidence measures how often B is in the basket when A is. Lift divides confidence by the support of B to show whether the pair occurs more often than chance.
How do I turn order lines into a basket table in Excel?
Use a PivotTable with the order ID in Rows and the product in Columns, counting products in Values. Then replace any count above 0 with 1 and empty cells with 0.
Should I divide by the number of baskets or the number of items?
By the number of baskets. Support is a share of baskets, so dividing by all items sold gives a different and misleading number.
What is a good minimum support threshold?
There is no universal value. It depends on the number of baskets and items, so analysts usually pick a threshold that keeps enough rules to act on while every rule still rests on a reasonable number of baskets.
Keep going: Market Basket Analysis: Support, Confidence, Lift & Cross-Selling
This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time $9.90.
- Pair Support with SUMPRODUCT: the Co-Occurrence Matrix
- Confidence A → B: How Often B Follows A
- Lift: Is the Rule Better than Chance?
- Leverage and Conviction: Size and Direction of a Rule
- Filtering Rules by Minimum Support and Confidence, Ranking by Lift
- The Apriori Idea: Pruning 3-Item Sets Before You Count Them
- From Rules to Cross-Selling: Expected Uplift per Recommendation
- From Receipt Lines to a 0/1 Basket Table
- How Sure Is a Rule? Standard Error and a Lower Bound for Confidence
- Beyond Lift: Cosine and Kulczynski, Measures that Ignore Empty Baskets
- Rules with Two Items on the Left: {A, B} → C and the Improvement Test
- Weekday vs Weekend: Does a Rule Hold in Both Segments?
- Rolling Items Up to Categories: Rules at the Right Level
- Bundle Discounts: Paying for Pairs You Already Sell
- Measuring a Placement Test: Attach Rate, Test Store vs Control Store
- A "Frequently Bought Together" Box: One Best Partner per Product
- Tracking a Rule Over Time: Monthly Lift and a Line Chart
- Basket Value: Do Baskets with an Item Spend More?
- Final Project: Cross-Selling Dashboard for a Second Store