Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query List.Percentile Function Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To use the List.Percentile function in Power Query, you must pass a list of numbers and a percentile value between 0 and 1 into a custom column or step formula. This function calculates the value below which a given percentage of data falls, providing a powerful way to identify outliers, benchmarks, or distribution thresholds in your datasets.

What You'll Need

  • Microsoft Excel or Power BI Desktop with Power Query enabled.
  • A dataset containing a column of numeric values (integers or decimals).
  • A basic understanding of how to enter a Custom Column formula in the Power Query Editor.

Step-by-Step

  1. Load your data into Power Query: Open Excel or Power BI, select your data source, and click 'From Table/Range' or 'Get Data' to open the Power Query Editor window.
  2. Identify your numeric column: Ensure the column you wish to analyze is set to a numeric data type (Decimal Number, Whole Number, or Currency). If the icon next to the column header shows 'ABC', right-click the header, select 'Change Type', and choose 'Decimal Number'.
  3. Create a new Custom Column: Navigate to the 'Add Column' tab on the top ribbon and click 'Custom Column'. A dialog box will appear.
  4. Enter the List.Percentile formula: In the 'Custom column formula' box, you need to transform your column into a list and then apply the function. If your column is named 'Sales', type the following formula: List.Percentile(TableName[Sales], 0.9). Note that TableName refers to the name of your previous step (usually 'Source' or 'Changed Type'), but in a Custom Column context, you can often simply use the column name wrapped in a list conversion if you are grouping, or more commonly, you use it within a grouping context. To get a single value for the entire column, use: List.Percentile(#"Previous Step Name"[ColumnName], 0.5).
  5. Understand the arguments: The first argument is the list of numbers. The second argument is the percentile as a decimal. For example, 0.5 represents the median, 0.25 represents the first quartile, and 0.9 represents the 90th percentile.
  6. Handle Grouping (Advanced): If you want the percentile for different categories (e.g., percentile of sales per region), first go to the 'Transform' tab and select 'Group By'. Choose your category column, set the operation to 'All Rows', and name the new column 'Data'. Then, add a Custom Column using the formula: List.Percentile([Data][Sales], 0.9). This tells Power Query to look at the 'Sales' column inside the nested table created for each group.
  7. Apply and Close: Once the formula is entered, click 'OK'. Review the new column to ensure the values are correct. Click 'File' > 'Close & Apply' to load the results back into your spreadsheet or model.

Common Mistakes

One of the most frequent errors is passing a column reference directly without converting it to a list format. In Power Query, a column is technically a series of values, but the List.Percentile function specifically requires the List data type. If you try to use List.Percentile([ColumnName], 0.5) inside a standard Custom Column row-by-row calculation, it will fail because the function is looking for a list of all values, but the row context only provides a single value. This is why the 'Group By' method or referencing the previous step name is essential.

Another mistake is using whole numbers for the percentile argument. Users often attempt to type 90 for the 90th percentile. However, the function requires a value between 0 and 1. Entering 90 will result in an error because it falls outside the valid mathematical range for a percentile calculation. Always use 0.9 instead of 90, or 0.5 instead of 50.

Data type mismatches are also a significant hurdle. If your numeric column contains any 'null' values or text strings that cannot be converted to numbers, the function may return an error or produce unexpected results. While List.Percentile is generally robust with nulls, it is best practice to filter out nulls or replace them with zeros before performing statistical calculations to ensure the distribution is not skewed or broken by non-numeric entries.

Tips

To make your formulas more dynamic, instead of hardcoding 0.9 into your Custom Column, you can reference a single cell from an Excel table or a Power BI parameter. This allows you to change the percentile threshold (e.g., moving from the 90th to the 95th percentile) without ever opening the Power Query Editor again.

When working with large datasets, calculating percentiles across millions of rows can be resource-intensive. If you find your refresh times are slowing down significantly, consider performing the grouping and percentile calculation as early as possible in your query steps to reduce the amount of data being processed in subsequent transformations.

For better readability in your M code, use the 'Advanced Editor' to rename your steps clearly. When you use the syntax #"Step Name"[ColumnName], having descriptive step names makes it much easier to debug which part of the data pipeline is feeding into your statistical function.

Troubleshooting

If you encounter an error, follow these steps in order:

  1. Check for Error Messages: Hover over the 'Error' cell in your new column. If it says 'We cannot convert the value to type List', it means you are passing a single value instead of a list. Ensure you are using the TableName[ColumnName] syntax or the [Data][ColumnName] syntax within a grouped table.
  2. Verify Data Types: Go to the step immediately preceding your calculation. Look at the icon in the column header. If it isn't a number icon (like 1.2 or 123), the function will not work. Use 'Change Type' to fix this.
  3. Check the Percentile Range: Ensure your second argument is a decimal between 0 and 1. If you see an error regarding 'out of range' or 'invalid argument', check this value first.
  4. Inspect for Nulls and Errors: If the result is an error, select your source column, go to 'Home' > 'Remove Rows' > 'Remove Errors' (note: this deletes the rows, so use with caution) or use 'Replace Errors' to see if a specific data point is breaking the calculation.
  5. Step Name Syntax: If you are referencing a previous step, ensure the name is exact. If the step name contains spaces, it must be written as #"Step Name". A single typo here will cause the entire query to fail.

Frequently Asked Questions

How do I calculate the median using this function?

The median is mathematically equivalent to the 50th percentile. Simply use 0.5 as your second argument: List.Percentile(YourList, 0.5).

Can I use List.Percentile on a column with text?

No. The function requires a list of numbers. If your column contains text, you must first remove the text or convert the column to a numeric type. If conversion fails, the rows will show errors.

What is the difference between List.Percentile and List.Median?

There is no functional difference in the result; List.Median is simply a specialized, more readable shortcut for List.Percentile(List, 0.5). Using List.Median can make your code easier for others to read.

Does the order of the numbers in the list matter?

No. The function automatically handles the sorting required to determine the percentile. You do not need to sort your column manually before applying the function.

Why does my percentile return a null value?

This usually happens if the list being passed is empty or if the entire column consists of null values. Ensure your filters are not accidentally removing all data before the calculation step.

Can I calculate multiple percentiles at once?

You cannot do it in a single function call, but you can create multiple Custom Columns—one for the 25th percentile, one for the 50th, and one for the 75th—to get a full distribution view of your data.

)