Power Query List.StandardDeviation: How to Use It
In this article
The List.StandardDeviation function in Power Query returns the sample standard deviation of a list of numbers — a single number that tells you how spread out the values are around their average. It is the M formula equivalent of Excel's STDEV.S, and you use it inside the Power Query Editor, not in a worksheet cell. To use it you need a numeric list (a column converted to a list, or a literal list such as {1,2,3,4}) and a query step where you can enter a custom formula.
What You'll Need
- Power BI Desktop, Excel (Power Query is built into Excel 2016 and later, and Microsoft 365), or another host that includes the Power Query Editor.
- A query that already loads, or contains, numeric values. Text, nulls and errors will cause the function to behave differently, so clean the column first.
- Basic familiarity with the Power Query Editor: the Queries pane, the formula bar, and the Applied Steps list. Menu labels can differ slightly by version, device and region.
Step-by-Step
- Open the Power Query Editor. In Excel, select a cell in your data and go to Data > Get & Transform Data > From Table/Range (or use an existing query). In Power BI Desktop, use Home > Transform Data. The editor opens in a separate window.
- Confirm the column is numeric. Select the column header. Its data type icon appears on the left of the header. If it shows ABC or a calendar, click the icon and choose Decimal Number or Whole Number.
List.StandardDeviationneeds numbers; text values will throw an error. - Remove or handle blanks and errors first. Right-click the column header and use Remove Empty (or filter out nulls), and use Remove Errors if any cells show Error. Nulls are ignored by the function in most cases, but errors are not, and a single error in the list will make the whole result an error.
- Turn the column into a list. With the column selected, go to the Transform tab and choose Convert to List (in some versions it appears under a dropdown on the Transform tab). The step is added as
Table.Column(#"Previous Step", "YourColumn")in the formula bar. If you prefer, you can skip this and reference the column directly in the next step. - Add a custom step with the function. Go to Home > Advanced Editor if you are comfortable editing M directly, or add a step via Add Column > Custom Column. In the Custom Column dialog, enter a formula such as
List.StandardDeviation(#"Converted to List")and give the column a name like StdDev. Click OK. - Check the result. Because the function returns a single scalar value, every row of the new column will show the same number — that is expected. If you only want the value once, you can instead use Home > Advanced Editor to create a standalone step:
StdDevValue = List.StandardDeviation(#"Converted to List"), then referenceStdDevValuewherever you need it. - Use the value. You can keep it as a query that returns one number, merge it back into your main table, or use it in a subsequent calculation such as a z-score:
(each [Value] - List.Average(MyList)) / StdDevValue. Close and load when finished.
Common Mistakes
- Passing a table or column instead of a list.
List.StandardDeviationexpects a list. A table column reference works only after conversion withTable.Columnor Convert to List; passing the table itself returns an error. - Leaving text in a numeric column. A single text value such as "N/A" causes an error. Change the type and filter out non-numeric rows before calling the function.
- Expecting a population standard deviation. This function calculates the sample standard deviation (divides by n−1). If you need the population version, use
List.StandardDeviationonly when your data is a sample; for a full population, compute it manually withList.SumandList.Countor use a different approach. - Forgetting that errors propagate. An error anywhere in the list makes the result an error. Clean the column first.
- Hard-coding a column name. If you rename the column later, the step breaks. Use the exact name shown in the formula bar, or reference the step name.
Tips
- Test the function with a small literal list in a blank query: Home > New Source > Blank Query, then in the formula bar type
= List.StandardDeviation({1,2,3,4,5}). This confirms the syntax before you apply it to real data. - Use
List.Averagealongside it to report mean and spread together. - If your data has outliers, consider whether standard deviation is the right measure; median absolute deviation may describe the spread better, though Power Query has no built-in function for it, so you would build it with
List.MedianandList.Transform. - Keep the list step separate from the calculation step so you can inspect the list in the preview pane.
Troubleshooting
If the custom column shows Error, click the error cell to see the message. "We cannot convert the value ... to type Number" means a text value slipped through — change the type and filter. "The field 'X' of the record wasn't found" means the column name in your formula no longer matches; check the exact spelling in the formula bar. If the result is blank, the list is probably empty after filtering; check the row count in the preview. If the number looks wrong, confirm you are using a sample rather than a population, and check whether nulls were removed or included. If the whole query fails after editing, open Advanced Editor and compare the step names with the Applied Steps list; a renamed step is the usual culprit. As a last resort, delete the failing step and rebuild it from the ribbon rather than editing M by hand.
Frequently Asked Questions
Does List.StandardDeviation calculate sample or population standard deviation?
It returns the sample standard deviation, dividing by n−1. Use it when your values are a sample of a larger population.
Can I use it on a column without converting to a list?
Yes, if you reference the column through Table.Column, which returns a list. The Convert to List button simply writes that step for you.
Why do all rows show the same number?
Because the function returns one scalar value, not a row-by-row result. That is expected; the value is the same for every row.
What happens if the list contains nulls?
Nulls are generally ignored in the calculation, but errors are not. Remove errors and decide whether to remove nulls before calculating.
Is there a population standard deviation function?
Power Query does not provide a separate built-in population function. For a full population you would need to compute it manually from the list.
Can I use it in Excel Power Query as well as Power BI?
Yes. The M engine is the same, so the function works in Excel's Power Query Editor and in Power BI Desktop.