Smart Systems for Home

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

Power Query List.Mode Function: Usage and 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

The List.Mode function in Power Query is used to identify the most frequently occurring value (the statistical mode) within a list of data. Unlike List.Average or List.Median, which calculate a central tendency based on numerical value, List.Mode identifies the value that appears most often, making it compatible with both numeric and text-based data. To use it, you simply provide a list as the input argument, and the function returns the single most common item found in that list.

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • The Power Query Editor window open.
  • A dataset containing a column of values (numbers, text, or dates) that you wish to analyze for the most frequent occurrence.
  • Basic familiarity with the Power Query formula bar, as List.Mode is an M function that is typically entered manually rather than selected from a ribbon menu.

Step-by-Step

  1. Load Your Data: Open Power Query by going to the Data tab in Excel and selecting Get Data, or by clicking Transform Data in Power BI. Ensure your table is loaded into the Power Query Editor.
  2. Isolate the Column as a List: The List.Mode function requires a list as its input, not a table. If you try to apply the function to a whole table, it will return an error. To convert a column to a list, you can right-click the column header and select Drill Down. This transforms the current step from a table to a list. Note that labels and menu options may differ slightly depending on your software version or region.
  3. Create a Custom Step: If you do not want to lose your table structure, do not use Drill Down. Instead, click the fx icon next to the formula bar. This creates a new custom step in the Applied Steps pane.
  4. Enter the Formula: In the formula bar, type = List.Mode(NameOfPreviousStep[ColumnName]). Replace NameOfPreviousStep with the name of the step immediately preceding the current one (usually something like #"Changed Type") and ColumnName with the exact name of the column you are analyzing, enclosed in square brackets.
  5. Execute the Calculation: Press Enter. Power Query will process the list and return a single scalar value representing the most common item in that column.
  6. Convert Back to Table (Optional): If you need this mode value as a new column in your original table rather than a standalone value, you should use a Custom Column instead. Go to the Add Column tab > Custom Column. In the dialog box, enter List.Mode(PreviousStepName[ColumnName]). This will repeat the mode value for every row in the table.
  7. Verify the Result: Check the output against a small sample of your data to ensure the value returned is indeed the one that appears most frequently.

Common Mistakes

One of the most frequent errors users encounter is passing a Table object into the function instead of a List object. In Power Query, a Table is a two-dimensional grid, while a List is a one-dimensional sequence. If your formula looks like = List.Mode(Source) and "Source" is a table, the function will fail. You must specify the column using the syntax Source[ColumnName] to extract the list from the table.

Another common mistake is ignoring case sensitivity. Power Query is case-sensitive. If your list contains "Apple", "apple", and "Apple", the mode will be "Apple" with a count of two. However, if the list contains "Apple" and "apple", Power Query treats these as two distinct values. If you want to find the mode regardless of capitalization, you must first transform the column to lowercase or uppercase using Transform > Format > lowercase before applying the List.Mode function.

Users also often confuse List.Mode with List.Median. While both are measures of central tendency, the median is the middle value of a sorted list, whereas the mode is the most frequent. For a list like {1, 2, 2, 3, 10}, the median is 2 and the mode is 2. But for a list like {1, 2, 2, 3, 3, 3, 10}, the median is 3 and the mode is 3. In a list like {1, 2, 2, 10, 10, 10}, the median is 2 but the mode is 10.

Tips

To handle datasets where multiple values appear with the same maximum frequency (a multimodal distribution), be aware that List.Mode only returns the first value it encounters that hits the maximum count. If you need to find all values that tie for the mode, you cannot use List.Mode alone. Instead, you should group the data by the column, count the rows for each group, sort the counts in descending order, and then filter for all rows that match the top count.

For better performance on very large datasets, ensure that your data types are correctly defined before calling the function. While List.Mode works on any data type, having a consistent type (e.g., ensuring all values are Text) prevents unexpected errors and can slightly improve processing speed during the grouping phase that occurs under the hood of the function.

If you are using the mode as part of a data cleaning process (for example, filling in missing values with the most common value), you can create a variable for the mode using a Let statement in the Advanced Editor. This prevents Power Query from recalculating the mode for every single row in your table, which can drastically reduce refresh times.

Troubleshooting

If you receive a "Expression.Error: We cannot convert the value... to type List" error, this confirms that you are passing a table or a single value into the function. Check your formula and ensure you have used the TableName[ColumnName] syntax. If the table name contains spaces, it must be wrapped in quotes and preceded by a hashtag, such as .

If the function returns a value that you believe is incorrect, check for trailing or leading spaces in your text data. A value of "New York" and "New York " (with a trailing space) are treated as different entities. Use the Transform > Trim function on your column before calculating the mode to remove these invisible characters.

If the formula bar is not visible, you cannot easily enter the List.Mode function. Go to the View tab and check the box for Formula Bar. If the result is null, ensure that the list you are referencing is not empty and does not consist entirely of null values, as the mode of a list of nulls may return null depending on the version and data context.

Frequently Asked Questions

Can List.Mode be used on text columns?

Yes, List.Mode works perfectly on text, numbers, and dates. It simply counts occurrences of identical values regardless of the data type.

What happens if there is a tie for the most frequent value?

The function returns the value that appears first in the list among those that share the highest frequency. It does not return a list of all modes.

Is List.Mode available in the standard ribbon menus?

No, there is no button for "Mode" in the Power Query ribbon. You must enter it manually in the formula bar or through a Custom Column dialog.

Does List.Mode ignore null values?

No, List.Mode treats nulls as a valid value. If null is the most frequent entry in your list, the function will return null. To avoid this, filter out nulls before applying the function.

How is List.Mode different from the MODE.SNGL function in Excel?

While they achieve the same statistical goal, List.Mode is written in M language for Power Query and can handle text, whereas Excel's MODE.SNGL is a worksheet function that only works with numeric data.