Code Generator | DAX

Exploring the MAXX Function in DAX

The MAXX function in DAX evaluates an expression for each row of a table, returning the maximum value of those evaluations. It's ideal for aggregating data with row-wise calculations in Power BI and Microsoft tools.


Empty image or helper icon

Prompt

explains MAXX functions

Answer

Understanding the MAXX Function in DAX

Overview

The MAXX function in DAX is used to evaluate an expression for each row of a table and return the maximum value resulting from that evaluation. It is particularly useful for aggregating data where you need to perform row-wise calculations and then determine the highest result.

Syntax

MAXX(, )

Parameters

  • <table>: The table or a table expression that you want to evaluate.
  • <expression>: The expression evaluated for each row of the table.

Return Value

  • Returns the maximum value of the expression evaluated across the specified table.

Exceptions

  • If the specified table is empty, MAXX will return a blank value.
  • If the expression results in errors for all rows, it will return an error.

Example Usage

The following example demonstrates how to use the MAXX function effectively.

Scenario

Assume we have a Sales table with the following structure:

Product SalesAmount Discount
Product A 100 10
Product B 150 15
Product C 200 20

Objective

We want to find the maximum sales amount after applying discounts.

DAX Code Example

Max_Sales_After_Discount = 
MAXX(
    Sales,
    Sales[SalesAmount] - Sales[Discount]
)

Explanation

  1. Data Table: The function begins by taking the Sales table as input.
  2. Expression Evaluation: For each row in the Sales table, it calculates Sales[SalesAmount] - Sales[Discount].
  3. Max Calculation: The function will evaluate the resulting values for each row and return the maximum.

Result

In the above table, the calculated sales amounts after discounts are:

  • Product A: 90
  • Product B: 135
  • Product C: 180

Thus, Max_Sales_After_Discount will return 180, which corresponds to Product C.

Key Points

  • MAXX is used to find the maximum after evaluating an expression across a table.
  • Effective for scenarios requiring calculations based on row data.
  • Handles both numerical and non-numerical evaluations depending on the expression provided.

Conclusion

The MAXX function is a powerful tool in DAX when you need to aggregate values based on evaluations. Understanding its syntax and application allows data scientists to leverage DAX effectively in Power BI and other Microsoft tools. For further learning on DAX and its applications, consider exploring resources available on the Enterprise DNA Platform.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

The MAXX function in DAX evaluates an expression for each row of a table, returning the maximum value of those evaluations. It's ideal for aggregating data with row-wise calculations in Power BI and Microsoft tools.