DSTDEV Function in Excel

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The DSTDEV function calculates the standard deviation of the numbers in one column of your data, but only for the rows that meet the conditions you set. In simple terms, it tells you how much those numbers spread out around their average.

DSTDEV treats the matching rows as a sample, a small part of a bigger group, which is usually what you have. If your rows cover the whole group, its sibling function DSTDEVP is the better fit.

Like the other database functions in Excel, DSTDEV reads its conditions from a few cells on the sheet, not from inside the formula.

In this tutorial, I’ll show you how to use it with one condition, multiple conditions, dates, several columns at once, and a formula as the condition, plus how to handle the #DIV/0! error.

Follow along with the example file

DSTDEV Function Examples.xlsx

Download

DSTDEV Function Syntax

Here is the syntax of the DSTDEV function:

=DSTDEV(database, field, criteria)
  • database – The whole data range, including the header row. Each row is a record and each column is a field.
  • field – The column you want the standard deviation of. You can give its header in double quotes (like “Score”) or its position in the database as a number (like 3 for the third column).
  • criteria – The range that holds your conditions. Its top row has headers that match the headers in your data, and the conditions go in the cells right below them.

How you lay out the criteria range decides how the conditions combine. Conditions on the same row must all be true (Example 3), while conditions on separate rows mean any one of them can be true (Example 4).

If the cell under a criteria header is empty, that header puts no limit on the rows. So if it’s your only condition, every row matches and you get the standard deviation of the whole column.

The DSTDEV function works in Excel for Microsoft 365, Excel 2024, 2021, 2019, and 2016, on both Windows and Mac.

When to Use the DSTDEV Function

Use this function when you need to:

  • Find how much the values vary for one group in your data, such as one player, one product, or one store
  • Get the standard deviation of rows that meet several conditions at once, or any one of several conditions
  • Measure the spread of values for rows whose date or number falls between two limits, with the limits kept in cells you can change
  • Check the consistency of a sample, where the rows you have stand in for a bigger group

Let me show you a few practical examples of how to use the DSTDEV function.

Example 1: Conditional Standard Deviation for One Bowler

Let’s start with a simple example.

Below is a bowling league’s score sheet with each bowler’s score for four weeks, and I want to know how much Natalie’s scores vary, with the result in cell E5.

Bowling league scores with Natalie under the Bowler criteria header in E1:E2 and an empty Score Std Dev cell

Here is the formula:

=DSTDEV(A1:C13,"Score",E1:E2)
DSTDEV formula in E5 returning 16.78, the standard deviation of Natalie's scores

This gives us 16.78. The bigger this number, the more a bowler’s scores jump around from one game to the next.

In the above formula, A1:C13 is the full data with its headers, “Score” is the column to calculate on, and E1:E2 is the criteria range. The header in E1 tells DSTDEV which column to check, and E2 holds the bowler’s name.

Since the name sits in a cell, you can type Sandra in E2 and the result changes to 5.48. Her scores are much closer together, which means she’s the more consistent bowler.

These four games are only a sample of how each person bowls, and future games will add more. That’s why DSTDEV, which treats the rows as a sample, is the right pick here.

Under the hood, DSTDEV gives the same result as the STDEV function run on only Natalie’s four scores, because both treat the numbers as a sample.

Important: The criteria header must match the data header exactly. If E1 said Bowlers instead of Bowler, no row would match, and DSTDEV would return a #DIV/0! error.

I placed the criteria range to the right of the data on purpose. Microsoft recommends not putting it below your data, because that’s where new rows usually get added.

Example 2: Standard Deviation With a Number Condition (Field as a Column Number)

Here’s another practical scenario.

Below is a gym’s class log with the length of each class in minutes and the calories burned, and I want the standard deviation of calories for classes that are 45 minutes or longer, with the result in E5.

Gym class log with >=45 under the Minutes criteria header and an empty Calories Std Dev cell

Here is the formula:

=DSTDEV(A1:C12,3,E1:E2)
DSTDEV formula using 3 as the field returning 150.0 for classes of 45 minutes or more

This returns 150.0, the standard deviation of calories burned in the eight classes that ran 45 minutes or more.

The condition in E2 is >=45, typed straight into the cell. Any comparison operator works the same way, such as >30, <60, or <>45.

This time, I used 3 as the field instead of “Calories”. Since Calories is the third column in A1:C12, DSTDEV uses that column.

A column number is quicker to type, but it can quietly point to the wrong column. If someone inserts a column inside the data, 3 now refers to a different field, while “Calories” keeps working.

Example 3: DSTDEV With Multiple Criteria (AND)

Now let’s look at rows that need to meet two conditions at the same time.

Below is a list of gas stations with each station’s brand, fuel type, and price per gallon, and I want to see how much the Premium price varies across Shell stations, with the result in E5.

Gas station prices with Shell and Premium on one criteria row under Brand and Fuel Type and an empty Price Std Dev cell

Here is the formula:

=DSTDEV(A1:C13,"Price per Gallon",E1:F2)
DSTDEV formula with two criteria returning $0.198 for Shell Premium prices

This gives us $0.198, which comes from the four Shell stations that sell Premium.

The criteria range now has two headers, Brand and Fuel Type, and both conditions sit on the same row. When conditions share a row, a station is counted only if it meets all of them.

One thing to know about text conditions is that they match values that begin with that text. So Shell in E2 would also pick up a brand called Shell Express, if your list had one.

To match only Shell exactly, enter =”=Shell” in E2 instead.

You can also use wildcards for partial matches, the same way as in the DSUM function. An asterisk (*) stands for any number of characters, so *ell matches Shell, while a question mark (?) stands for exactly one character, as in ?hell.

Example 4: Standard Deviation for Either Condition (OR)

This next one shows how to include rows that match one value or another.

Below is a list of flights with the airport each one left from and its arrival delay in minutes, and I want the standard deviation of delays for flights from JFK or LGA, with the result in E6.

Flight delays with JFK and LGA on separate rows under the From criteria header and an empty Delay Std Dev cell

Here is the formula:

=DSTDEV(A1:C13,"Delay (min)",E1:E3)
DSTDEV formula with OR criteria rows returning 20.5 for flights from JFK or LGA

This returns 20.5, the standard deviation of delays for the seven flights that left from JFK or LGA.

The OR logic comes from the layout. JFK and LGA are on separate rows under the same From header, and separate rows work as OR, so a flight counts if it matches either airport.

Important: Make sure the criteria range has no empty rows. If you used E1:E4 here, the blank row would match every flight, and you’d get 18.6, the standard deviation of all twelve delays.

Example 5: Standard Deviation Between Two Dates

Let’s step it up with a date range you can change without touching the formula.

Below is a library’s log of daily book checkouts, and I want the standard deviation of checkouts between the start date in D2 and the end date in E2, with the result in D8.

Library daily checkouts with start and end dates in D2:E2, the date criteria in D4:E5 and an empty Checkouts Std Dev cell

Here is the formula:

=DSTDEV(A1:B13,"Checkouts",D4:E5)
DSTDEV formula returning 45.1 for checkouts from September 3 to September 9, 2026

This gives us 45.1, the standard deviation of checkouts from September 3 to September 9, 2026.

The criteria range D4:E5 uses the Date header twice on the same row. Since conditions on one row must all be true, a day is counted only if it’s on or after the start date and on or before the end date.

The two conditions are formulas. D5 has =”>=”&D2 and E5 has =”<=”&E2, which join each comparison operator with the date in D2 or E2.

They show up as >=46268 and <=46274 because Excel stores dates as serial numbers, and 46268 is September 3, 2026. To look at a different week, just change the dates in D2 and E2.

Example 6: Fix the #DIV/0! Error When Fewer Than Two Records Match

Now let’s see what happens when there isn’t enough data to work with.

Below is a vet clinic’s list of dogs with each dog’s breed and weight, and I want the standard deviation of weights for Labradors in E5 and Beagles in G5.

Vet clinic dog weights with Labrador and Beagle criteria blocks and empty Labrador Std Dev and Beagle Std Dev cells

Here is the formula for the Labradors:

=DSTDEV(A1:C11,"Weight (lbs)",E1:E2)
DSTDEV formula in E5 returning 6.4 for the four weighed Labradors

This returns 6.4. There are five Labradors, but Daisy’s weight says Not weighed, so DSTDEV works with the other four.

Text and blank cells in the field column are skipped, not treated as zero. That’s what you want here, because a missing weight isn’t a weight of 0.

And here is the same formula for the Beagles:

=DSTDEV(A1:C11,"Weight (lbs)",G1:G2)
DSTDEV formula in G5 returning #DIV/0! because only one Beagle matches

This returns a #DIV/0! error, because Bella is the only Beagle. A sample standard deviation needs at least two values, since it divides by the number of values minus one, and that’s zero here.

The DSTDEVP function would return 0 for the same Beagle, because it treats Bella as the whole group, the same way the STDEV.P function does. For a sample, though, one dog tells you nothing about how much Beagle weights vary, so the error makes sense.

To show a message instead, check the count first. Here is the formula in G8:

=IF(DCOUNT(A1:C11,"Weight (lbs)",G1:G2)<2,"Need 2+ dogs",DSTDEV(A1:C11,"Weight (lbs)",G1:G2))
IF and DCOUNT formula in G8 showing Need 2+ dogs instead of the error

The DCOUNT function uses the same database, field, and criteria, and counts how many numbers DSTDEV would use. Since that count is 1, the formula shows Need 2+ dogs instead of the error.

You could wrap DSTDEV in the IFERROR function instead, but that hides every error, including the #VALUE! you’d get from a misspelled field name. The DCOUNT check only catches the case of too few values.

Example 7: Get the Standard Deviation of Two Columns at Once

DSTDEV usually returns one value, but in Microsoft 365 it can return results for several columns with one formula.

Below is a list of recipes with each recipe’s cuisine, prep time, and cook time in minutes, and I want the standard deviation of both the prep time and the cook time for Italian recipes in F5:G5.

Recipe list with Italian under the Cuisine criteria header and empty Prep Time and Cook Time result cells

Here is the formula:

=DSTDEV(A1:D11,{"Prep Time","Cook Time"},F1:F2)
DSTDEV formula with an array of two field names spilling 33.5 and 19.2 into F5:G5

This returns 33.5 for prep time and 19.2 for cook time, across the five Italian recipes.

Instead of one header, the field argument gets a list of headers inside curly brackets. DSTDEV returns one result for each header, and the results spill into F5 and G5.

Prep time varies a lot more here, mostly because the pizza needs 90 minutes of prep while most of the other recipes need 10 to 30.

Important: Type the headers inside the curly brackets. If you point the field argument at a range of several header cells (like F4:G4), DSTDEV returns #VALUE! instead of spilling.

If the cell next to F5 isn’t empty, you’ll see a #SPILL! error until you clear it.

If your version of Excel doesn’t spill the result (Excel 2019 or earlier, for example), enter the below formula in cell F5 and then copy it to G5:

=DSTDEV($A$1:$D$11,F$4,$F$1:$F$2)

This version points the field argument at a single header cell in row 4 (F$4, which becomes G$4 in the copy), so each copy picks up its own column.

A single cell works fine as the field. It’s only a range of several cells that returns #VALUE!.

Example 8: Use a Formula as the Criteria in DSTDEV

Let’s end with a condition that compares two columns in the same row.

Below is a list of concert tickets with each ticket’s face value and the price it resold for, and I want the standard deviation of resale prices for tickets that sold above face value, with the result in E5.

Concert ticket list with the formula =C2>B2 under the Above Face Value header and an empty Resale Std Dev cell

Here is the formula:

=DSTDEV(A1:C11,"Resale Price",E1:E2)
DSTDEV formula with a formula criterion returning $109.88 for tickets resold above face value

This returns $109.88, the standard deviation of the seven tickets that resold for more than face value.

How this formula works:

  • E2 holds the formula =C2>B2, which checks whether the resale price is higher than the face value. It’s written for the first ticket, in row 2.
  • DSTDEV runs that check again for every ticket, moving it down one row at a time. That’s why C2 and B2 have no dollar signs.
  • E2 shows TRUE because it only displays the result for the first ticket ($310 against $150). That doesn’t affect the DSTDEV result.
  • The header in E1 is Above Face Value, which doesn’t match any column in the data. A formula condition needs a header like that, because a header that matches a column (like Resale Price) makes DSTDEV return #DIV/0!.

Important: Keep C2 and B2 as relative references. If you lock them as $C$2>$B$2, every ticket gets the first ticket’s answer (TRUE), so all ten count and you get $112.69, the standard deviation of all ten resale prices.

So these are some practical ways to use the DSTDEV function in Excel. I covered single conditions, AND and OR conditions, dates, the #DIV/0! error, several columns at once, and a formula as the condition.

I hope you found this Excel tutorial useful.

List of All Excel Functions

Other Excel Articles You May Also Like:

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.