Use the MAX function in a DAX measure to return the highest value from a single column or a table expression, or MAXX for a row-by-row calculation across a table. This is the most direct way to identify the peak value in your dataset without creating a separate ranking column.
What You'll Need
- A working Power BI Desktop or Service account with access to a dataset.
- A table or dataset containing numerical data (e.g., Sales, Temperature, or Quantity).
- A basic understanding of DAX (Data Analysis Expressions) syntax for Power BI.
Step-by-Step
To find the maximum value in a column, use the MAX function. To find the maximum result of a custom calculation applied to each row in a table, use the MAXX function.
Method 1: Using the MAX Function
- Open Power BI Desktop or Service. Navigate to the report view and select the visual you want to edit, such as a card, table, or KPI card.
- Open the Measure Tool. Look for the "Measure" button in the top ribbon or right-click a blank area of the Fields pane and select "New Measure." Alternatively, select "New Quick Measure" for a guided setup.
- Write the DAX formula. Click into the formula bar and type the
MAXfunction. The syntax requires a column name or an expression that results in a table. - Define the scope. For a simple column maximum, type
MAX('TableName'[ColumnName]). Replace 'TableName' and [ColumnName] with your actual table and column names. Ensure the table name is wrapped in single quotes. - Verify the visual. The visual will now display the highest number found in that column for the current context (e.g., the highest sales figure for the selected year or region). If the visual is a table, the measure will appear as a new column in the table.
Method 2: Using the MAXX Function
Use MAXX when you need to calculate a value for each row in a table and then find the maximum of those results. This is useful for finding the highest total sales per customer or the highest quantity sold per item.
- Select the visual. Click on the report element where you want the result to appear.
- Create a New Measure. Go to the Home ribbon and click "New Measure." This creates a calculated field that can be added to visuals.
- Enter the MAXX syntax. Type
MAXX(to start the function. - Specify the table. Enter the table name followed by a comma. For example,
MAXX('SalesTable',. - Enter the expression. Inside the parentheses, write the calculation you want to perform for each row. For example, to find the top total sales per customer, type
'SalesTable'[Quantity] * 'SalesTable'[UnitPrice]. This multiplies the quantity by the price for every row. - Close the function. Type
)to close the MAXX function. The full formula should look likeMAXX('SalesTable', 'SalesTable'[Quantity] * 'SalesTable'[UnitPrice]). - Apply the visual. Drag this new measure into your visual. The visual will calculate the product of quantity and price for every sales transaction and return the single highest value found.
Common Mistakes
One of the most frequent errors is confusing the MAX and MAXX functions. MAX only accepts a single scalar value (a number, date, or text) and a column. MAXX requires a table followed by an expression to evaluate. If you try to use MAX with a complex calculation that requires looking at multiple columns, the formula will fail.
Another common mistake is not handling the context correctly. If you are working in a matrix visual with rows and columns, the formula will return the maximum value for that specific intersection. For example, a measure showing MAX('Sales'[SalesAmount]) in a matrix will show the highest sales for that specific region and year, not the global maximum. To get the global maximum, you would need to use an ALL function to ignore the context filters, such as MAX(ALL('Sales'[SalesAmount])).
Tips
When working with dates, the MAX function returns the latest date, not necessarily the most recent date in terms of time. If your data contains time components, ensure your date columns are formatted correctly to avoid confusion between midnight and the start of the day.
For performance, it is generally faster to filter the data before applying the MAX function. If you have a table with millions of rows, first filtering by a date range or category will significantly reduce the calculation time for the measure.
Troubleshooting
If the result in your visual is incorrect or shows an error, check the following.
Error: "A single value for column... cannot be determined from the given data set"
This error occurs when the measure is trying to return a single number, but the context of the visual is ambiguous (e.g., a blank visual or a visual with no applicable data). Ensure the visual is populated with data that matches the table and column referenced in your formula.
Result is not updating
If you edit the formula and the visual does not update immediately, try clicking the "Refresh" button in the top ribbon or use the shortcut Ctrl + Alt + F5 to force a full refresh of the report.
Logic is wrong (e.g., showing the wrong maximum)
Review the table name and column name in your formula. It is easy to mistype a name, which causes the function to look in the wrong place. Double-check that you are using the correct table for the calculation.
Frequently Asked Questions
What is the difference between MAX and MAXA?
MAX ignores any logical values (TRUE/FALSE) and text in the column. MAXA converts logical values to 1 and text to 0 before finding the maximum, which can lead to unexpected results if your column contains text.
Can I use MAX to find the maximum text value?
Yes, you can use MAX to find the alphabetically last text value (e.g., the customer with the last name Z). The function compares text strings based on their ASCII values.
How do I find the maximum value across multiple columns?
You can nest the MAX functions. For example, MAX('Table'[Column1], 'Table'[Column2]) will return the highest value found in either of the two columns.
Why does my measure show a blank when I use MAX?
This usually happens if the column contains only blank values. The MAX function returns a blank if there are no non-blank values to compare.
Can I use MAX in a calculated column?
Yes, you can use MAX in a calculated column, but it is rarely useful there. A calculated column is calculated for every row in the table, so using MAX on the same column for every row would just return the same value for every row. Use MAX in measures instead.