How to Do a Chi-Square Test in Excel: Step by Step

To do a chi-square test in Excel, put your observed counts in a table and build a second table of expected counts. Each expected count is the row total times the column total, divided by the grand total. Then use =CHISQ.TEST(observed_range, expected_range) to get the p-value.
If the p-value is below your significance level, usually 0.05, the two variables are likely related. You can also calculate the chi-square statistic itself and compare it with a critical value from CHISQ.INV.RT.
This guide covers each step, from setting up the counts to reporting the result. It reproduces Microsoft's own example to check the method, then walks through a full example on plan choice by sales channel. Steps and formulas come from Microsoft's support pages, read on November 19, 2026.
What a chi-square test tells you
A chi-square test checks whether counts differ from what you would expect by chance. It works on categories, not on averages. Each observation falls into one group, such as "Online" or "In store," and you count how many fall into each.
Microsoft describes the purpose this way: "You can use χ2 tests to determine whether hypothesized results are verified by an experiment."
A chi-square test helps you answer questions like these:
- Do customers in different channels choose different plans?
- Do men and women answer a survey question differently?
- Did a new checkout page change how many people buy?
- Do defect types differ between two factories?
The test compares two tables. The observed table holds the counts you collected. The expected table holds the counts you would see if the variables had nothing to do with each other. The bigger the gap between them, the stronger the evidence of a relationship.
Test of independence or goodness of fit
There are two common versions of the chi-square test in Excel. They use the same function but different expected values.
| Test | Question | Expected counts come from |
|---|---|---|
| Test of independence | Are two categorical variables related? | Row total × column total ÷ grand total |
| Goodness of fit | Do counts match a known distribution? | Your hypothesized shares × the total |
This guide focuses on the test of independence, the most common use. A goodness-of-fit test follows the same steps with a single row or column. For example, you might test whether support tickets are spread evenly across five weekdays.
Microsoft explains how Excel sets the degrees of freedom. "If r > 1 and c > 1, then df = (r - 1)(c - 1)." For a single row or column, df is the number of cells minus one.
Set up the observed table
Put your counts in a simple grid. Rows are the categories of one variable. Columns are the categories of the other.
| Basic | Premium | Row total | |
|---|---|---|---|
| Online | 90 | 60 | 150 |
| In store | 70 | 30 | 100 |
| Phone | 40 | 60 | 100 |
| Column total | 200 | 150 | 350 |
In the sheet, place the labels in A2:A4 and the counts in B2:C4. Put the row totals in D2:D4 with =SUM(B2:C2) and fill down. Put the column totals in B5:C5 with =SUM(B2:B4) and fill right. The grand total in D5 is =SUM(B2:C4).
Follow these rules:
- Use counts, not percentages. The test needs raw frequencies.
- Count each observation once. Each customer appears in exactly one cell.
- Keep categories separate. A customer cannot be both Online and Phone.
- Check the totals. The grand total should match the number of observations.
If your data is a list of raw rows, build the counts first with a PivotTable or with COUNTIFS. Each cell of the grid is one COUNTIFS formula with two conditions.
Build the expected table
The expected table shows what the counts would look like if channel and plan were unrelated. Build it below the observed table, in the same shape.
The formula for each expected cell is the row total times the column total, divided by the grand total. Microsoft describes the expected range as "the ratio of the product of row totals and column totals to the grand total."
With the layout above, put the expected table in B9:C11. Enter this in B9:
=$D2*B$5/$D$5
Then fill it across to C9 and down to row 11. The dollar signs keep the row totals in column D and the column totals in row 5 fixed as you fill.
For this data, the expected counts are:
| Basic | Premium | |
|---|---|---|
| Online | 85.71 | 64.29 |
| In store | 57.14 | 42.86 |
| Phone | 57.14 | 42.86 |
Check one cell by hand. Online has 150 customers, Basic has 200, and the total is 350. So 150 × 200 ÷ 350 is about 85.71.
Microsoft adds a note on sample size. "Some statisticians suggest that each Eij should be greater than or equal to 5." Every expected count here is well above 5, so the test is appropriate.
Run CHISQ.TEST
With both tables in place, the test is one formula. Microsoft's syntax is CHISQ.TEST(actual_range,expected_range).
Enter this in an empty cell:
=CHISQ.TEST(B2:C4,B9:C11)
Excel returns the p-value. Microsoft explains what it means. CHISQ.TEST returns the probability that a statistic at least this high "could have happened by chance under the assumption of independence."
In plain terms, the p-value is the chance of seeing a gap this large if the variables were truly unrelated. A small p-value means the gap is unlikely to be chance alone.
Two errors are common. If the two ranges have a different number of cells, Excel returns #N/A. A single cell on its own also returns #N/A, because it has no degrees of freedom.
Do not include the totals in either range. Select only the counts, B2:C4 for observed and B9:C11 for expected.
Get the chi-square statistic and critical value
CHISQ.TEST gives only the p-value. Many reports also need the chi-square statistic itself. You can calculate it in one cell:
=SUMPRODUCT((B2:C4-B9:C11)^2/B9:C11)
This adds up (observed − expected)² ÷ expected for every cell, which is the chi-square formula.
Two related functions help you check the result:
- CHISQ.DIST.RT returns "the right-tailed probability of the chi-squared distribution." =CHISQ.DIST.RT(statistic, df) gives the same p-value as CHISQ.TEST.
- CHISQ.INV.RT works the other way. It returns the critical value for a chosen significance level. For example, =CHISQ.INV.RT(0.05, 2) gives the cutoff for 2 degrees of freedom.
If the statistic is larger than the critical value, the result is significant at that level. This is the same decision as checking whether the p-value is below 0.05.
Microsoft's own examples confirm the pair works together. In one, the formula =CHISQ.DIST.RT(18.307,10) returns 0.0500006. In the other, the formula =CHISQ.INV.RT(0.050001,10) returns 18.306973. Each function undoes the other.
Keep all of these cells near the tables, with a short label beside each one. A reader can then follow the test from counts to conclusion without opening the formula bar.
Very small p-values appear in scientific notation. A result like 6.6E-05 means 0.000066. Format the cell as a number with more decimal places if you want to see it written out.
Check the method with Microsoft's example
Before you trust your own sheet, reproduce Microsoft's example. It compares how men and women answered a question with Agree, Neutral, or Disagree.
| Answer | Men (actual) | Women (actual) | Men (expected) | Women (expected) |
|---|---|---|---|---|
| Agree | 58 | 35 | 45.35 | 47.65 |
| Neutral | 11 | 25 | 17.56 | 18.44 |
| Disagree | 10 | 23 | 16.09 | 16.91 |
Microsoft's formula is =CHISQ.TEST(A2:B4,A6:B8) and its result is 0.0003082. The page notes that "The χ2 statistic for the data above is 16.16957 with 2 degrees of freedom."
We rebuilt the calculation independently and got a statistic of about 16.17 and a p-value of 0.0003082. If your sheet matches, your formulas are set up correctly.
A worked example: plan choice by sales channel
Now return to the channel data. A software company wants to know whether customers who buy through different channels choose different plans.
The observed counts show some differences at a glance. Premium is 40% of Online sales, 30% of In store sales, and 60% of Phone sales. The chi-square test tells you whether those gaps are larger than chance would produce.
Here are the results:
| Measure | Formula | Result |
|---|---|---|
| Chi-square statistic | =SUMPRODUCT((B2:C4-B9:C11)^2/B9:C11) | 19.25 |
| Degrees of freedom | (3 − 1) × (2 − 1) | 2 |
| p-value | =CHISQ.TEST(B2:C4,B9:C11) | about 0.000066 |
| Critical value at 0.05 | =CHISQ.INV.RT(0.05,2) | about 5.991 |
The statistic of 19.25 is far above the critical value of 5.991. The p-value is well below 0.05. So plan choice and sales channel are related in this data.
The test says a relationship exists, but not where. To find it, compare each observed count with its expected count. Phone sold 60 Premium plans where about 42.86 were expected. In store sold 30 Premium plans where about 42.86 were expected. Those two cells drive most of the result.
A useful business reading follows. Phone customers lean toward Premium, perhaps because a salesperson explains the extra features. In store customers lean toward Basic. That is a question worth testing next, not a proven cause.
You can also measure the strength of the relationship. Cramér's V divides the statistic by the total and the smaller table dimension minus one, then takes the square root. Here it is about 0.23, a modest effect.
Sample size explains why a modest effect can still be highly significant. With 350 customers, even moderate differences in plan share are unlikely to be chance. With 35 customers, the same percentages might not reach significance. Report both the p-value and the effect size, so readers see how strong the pattern is as well as how certain.
Report the result
A clear report states the test, the degrees of freedom, the sample size, the statistic, and the p-value. In APA style, this example reads:
χ²(2, N = 350) = 19.25, p < .001
Add one sentence in plain language. For example: "Plan choice differed by sales channel, with Phone customers more likely to choose Premium."
For the full rules, see our guide on how to report statistics in APA format. For what "significant" does and does not mean, see what is statistical significance.
Do a chi-square test in Excel with AI
The formulas are short once the counts are ready. The slow part is often getting there: turning a raw export into a clean count table and checking which cells drive the result. An AI tool can do that work for you.
Here is the method in three steps, using Powerdrill Bloom.
Step 1: Upload your Excel or CSV file
Upload the file with your raw rows or your count table, such as a sales export with channel and plan columns. The Excel Calculations page says to "Upload your Excel file" and to make sure "your data is correctly formatted."
You do not need to build the count table first. Name the two columns you want to compare in the next step.
Step 2: Ask for the chi-square test in natural language
Describe the test you need. For example: "Run a chi-square test of independence between sales channel and plan. Show the expected counts, the statistic, and the p-value."
The page asks you to input "your desired calculation request in text," with examples like standard deviation and growth rate. Ask follow-up questions, such as which cells contribute most to the result.
Step 3: Get the result for your report
Review the statistic, the p-value, and the expected table. Then ask for a short written summary or a chart of the observed and expected counts for your report or slides.
Check the counts and the p-value against your own sheet before you share the result.
Common mistakes to avoid
These are the problems that come up most often with a chi-square test in Excel.
- Using percentages. The test needs raw counts. Percentages give wrong results.
- Including totals in the range. Select only the count cells.
- Small expected counts. If any expected count is below 5, combine categories or collect more data.
- Mismatched ranges. Observed and expected tables must have the same shape.
- Reading cause into the result. A significant test shows a relationship, not its cause.
- Ignoring which cells matter. Compare observed and expected counts to see where the difference is.
For comparing two averages instead of counts, see our guide on how to do a t-test in Excel. For survey answers on a scale, see how to analyze Likert scale data.
When your categories sit in a large export, try Powerdrill Bloom to build the counts and run the test.
Frequently asked questions
How do I do a chi-square test in Excel?
Put your observed counts in a table and build a matching table of expected counts. Then use =CHISQ.TEST(observed_range, expected_range) to get the p-value.
How do I calculate expected values for a chi-square test in Excel?
Multiply the row total by the column total and divide by the grand total. A formula like =$D2*B$5/$D$5 fills the whole expected table.
Does CHISQ.TEST return the chi-square statistic?
No. It returns the p-value. Calculate the statistic with =SUMPRODUCT((observed-expected)^2/expected), or find the critical value with CHISQ.INV.RT.
What does the p-value mean in a chi-square test?
It is the chance of seeing differences this large if the variables were unrelated. A p-value below 0.05 usually means the relationship is statistically significant.
What is the difference between CHISQ.TEST and CHITEST?
CHITEST is the older version of the function. Microsoft notes it may not be available in future versions of Excel, so use CHISQ.TEST.
Sources: Microsoft Support, CHISQ.TEST function · Microsoft Support, CHISQ.DIST.RT function · Microsoft Support, CHISQ.INV.RT function · Microsoft Support, CHITEST function.