Smart Systems for Home

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

Power Query List.Max Function Explained

· 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.Max function in Power Query returns the largest value from a list. It is part of the List functions family and is used in the M language, the formula language behind Power Query in Excel and Power BI. You can use it to find the maximum number, date, or text value in a column, a custom list, or a list generated by another function. The function is simple to write, but its behavior with empty lists, nulls, and different data types can surprise new users. This guide covers everything you need to use List.Max effectively.

What You'll Need

  • Power Query Editor open in Excel (Data > Get Data > Launch Power Query Editor) or Power BI Desktop (Home > Transform Data).
  • A data source with at least one column of numbers, dates, or text, or a place to create a custom list (e.g., an empty query).
  • Basic familiarity with adding a custom column or writing M formulas in the formula bar.

Step-by-Step

  1. Open Power Query Editor – In Excel, go to the Data tab and click “Get Data” > “Launch Power Query Editor”. In Power BI, click “Transform Data” from the Home tab. The editor opens with your data loaded.
  2. Select the column or create a list – You can apply List.Max to an existing column by referencing it, or you can create a list manually. For a column, note its name (e.g., “Sales”). For a manual list, you can type it directly in a formula.
  3. Add a custom column (common approach) – Go to the “Add Column” tab and click “Custom Column”. In the dialog, give the column a name like “Max Sales”. In the formula box, type List.Max([Sales]) if you have a column called Sales. Click OK. This creates a new column with the maximum value from the list in that row (if the column is a list type) or the maximum of the entire column if you use List.Max(Table.Column(YourTableName, "Sales")).
  4. Use the formula bar for a quick check – If you want to test List.Max without adding a permanent column, select an empty cell in the formula bar (when a query is selected) and type = List.Max({1, 5, 3}) then press Enter. The result shows 5. This works in the query's formula bar when you are editing a step.
  5. Apply to a whole column – To get the maximum of an entire column, you need to reference the column as a list. Use List.Max(Table.Column(PreviousStepName, "ColumnName")). For example, if your previous step is named “Changed Type” and your column is “Sales”, write List.Max(Table.Column(ChangedType, "Sales")). This returns a single value, which you can use in a new custom column or a measure.
  6. Handle nulls and empty lists – By default, List.Max ignores null values. If the list is empty, it returns null. If you want to treat nulls as a specific value, you can use the optional second parameter: List.Max(list, default). For example, List.Max({}, 0) returns 0 instead of null.
  7. Use with conditional logic – You can combine List.Max with List.Select to find the maximum among filtered values. For instance, List.Max(List.Select({1, 2, 3, 4}, each _ > 2)) returns 4.
  8. Create a list from a column with duplicates – If your column has duplicates, List.Max still returns the highest value. It does not remove duplicates; it only finds the maximum.

Common Mistakes

  • Using List.Max on a column reference directly – In Power Query, a column reference like [Sales] is not a list; it is a field accessor. You need to wrap it in Table.Column or use List.Max(Table.Column(...)). If you write List.Max([Sales]) in a custom column, it will error because [Sales] returns a value, not a list.
  • Forgetting the optional default parameter – When your list can be empty, List.Max returns null. This can cause errors in subsequent steps if you expect a number. Always provide a default value if null is not acceptable.
  • Assuming text max works alphabetically – List.Max on text lists returns the last value in alphabetical order (e.g., “apple” > “banana”? Actually “banana” is greater). It works, but it is case-sensitive and uses the sort order of the underlying comparer. If you need case-insensitive, use List.Max(list, null, Comparer.OrdinalIgnoreCase) as a third parameter.
  • Using List.Max on a column of lists – If your column contains lists (e.g., each cell has a list), List.Max([Column]) will not work; you need to use List.Transform to apply List.Max to each inner list.

Tips

  • Use List.Max with List.Combine – If you have multiple columns and want the global maximum, combine them first: List.Max(List.Combine({Table.Column(Prev, "Col1"), Table.Column(Prev, "Col2")})).
  • Leverage the third parameter for comparers – The third parameter of List.Max allows you to specify a comparer function. For example, List.Max(list, null, Comparer.OrdinalIgnoreCase) for case-insensitive text, or Comparer.FromCulture("en-US") for culture-specific sorting.
  • Use in measures in Power BI – In Power BI, you can use List.Max inside a DAX measure only if you convert to M? No, DAX has its own MAX function. List.Max is for M. In Power Query, you can create a custom column that calculates the max of a list from a related table.
  • Test with a small sample – Before applying to large data, test the formula on a few rows to ensure the list reference is correct.

Troubleshooting

Error: “Expression.Error: The column 'Sales' of the table wasn't found.” – This means the column name is misspelled or does not exist. Check the exact name in the table preview. Use the column header to copy the name.

Error: “We cannot convert the value null to type Number.” – This happens when List.Max returns null and you try to use it in a numeric operation. Provide a default value: List.Max(list, 0).

Result is null even though the list has values – Check if the list contains nulls. List.Max ignores nulls, but if all values are null, it returns null. Also check if the list is actually empty (e.g., due to a filter).

Unexpected result with dates – Dates are stored as numbers in Power Query, so List.Max works fine. If you get a number instead of a date, format the column as date after applying the function.

Performance issues on large datasets – List.Max over a large column can be slow. Consider using the “Group By” feature to calculate the maximum per group, which is optimized.

Frequently Asked Questions

Can List.Max return the maximum of a column without using Table.Column?

No, because a column reference in M is not a list. You must use Table.Column or a similar function to extract the column as a list.

Does List.Max ignore null values?

Yes, by default it ignores nulls. If all values are null, it returns null. You can change this behavior by providing a default value or using a comparer.

How do I find the maximum of multiple columns?

Combine the columns into one list using List.Combine, then apply List.Max to the combined list.

Can I use List.Max on a list of dates?

Yes, dates are stored as numbers, so List.Max works. The result will be a date if the list contains dates.

What is the difference between List.Max and List.MaxN?

List.Max returns a single maximum value. List.MaxN returns the top N values as a list. Use List.MaxN(list, 5) to get the five largest values.

Is List.Max case-sensitive for text?

By default, it uses the comparer of the list, which is case-sensitive. To make it case-insensitive, pass Comparer.OrdinalIgnoreCase as the third parameter.