Formula Generator | DAX

AVERAGEX Function in DAX Explained

The AVERAGEX function in DAX computes the average of an evaluated expression across rows in a table. This guide covers its syntax, usage examples, and applications for calculating simple, conditional, and weighted averages effectively.


Empty image or helper icon

Prompt

I want to see more examples of ways to use the AVERAGEX function in DAX

Answer

Using AVERAGEX in DAX

Overview

The AVERAGEX function in DAX evaluates an expression for each row of a table and returns the average of those values. This function is useful for calculating averages based on complex expressions, such as weighted averages or averages based on conditions.

Syntax

AVERAGEX(, )
  • <table>: The table that contains the rows to be evaluated.
  • <expression>: The expression that is evaluated for each row of the table.

Examples

Example 1: Simple Average Calculation

Calculate the average sales amount per transaction.

Average_Sales_Amount = AVERAGEX(Sales, Sales[SalesAmount])

Explanation:

  • Sales: Represents the table containing sales data.
  • Sales[SalesAmount]: The column containing the sales amount for each transaction.
  • AVERAGEX(Sales, Sales[SalesAmount]): Calculates the average sales amount per transaction.

Example 2: Conditional Average

Calculate the average sales amount for transactions where the sales amount is greater than $500.

Average_Sales_Above_500 = 
AVERAGEX(
    FILTER(Sales, Sales[SalesAmount] > 500),
    Sales[SalesAmount]
)

Explanation:

  • FILTER(Sales, Sales[SalesAmount] > 500): Filters the Sales table for transactions where the sales amount is greater than $500.
  • Sales[SalesAmount]: The column containing the sales amount for each transaction.
  • AVERAGEX(FILTER(Sales, Sales[SalesAmount] > 500), Sales[SalesAmount]): Calculates the average sales amount for the filtered transactions.

Example 3: Weighted Average

Calculate the weighted average price of products, where the weight is the quantity sold.

Weighted_Average_Price = 
DIVIDE(
    SUMX(Sales, Sales[Quantity] * Sales[UnitPrice]),
    SUM(Sales[Quantity])
)

Explanation:

  • SUMX(Sales, Sales[Quantity] * Sales[UnitPrice]): Calculates the total weighted price by multiplying the quantity sold by the unit price for each transaction and summing the results.
  • SUM(Sales[Quantity]): Sums the total quantity sold.
  • DIVIDE(SUMX(Sales, Sales[Quantity] * Sales[UnitPrice]), SUM(Sales[Quantity])): Divides the total weighted price by the total quantity sold to yield the weighted average price.

Example 4: Average of a Calculated Column

Calculate the average discount amount per transaction.

Average_Discount_Amount = 
AVERAGEX(
    Sales,
    Sales[SalesAmount] * Sales[Discount]
)

Explanation:

  • Sales: Represents the table containing sales data.
  • Sales[SalesAmount] * Sales[Discount]: Calculates the discount amount for each transaction.
  • AVERAGEX(Sales, Sales[SalesAmount] * Sales[Discount]): Calculates the average discount amount per transaction.

Practical Illustration

Scenario

A sales manager wants to evaluate the performance of sales agents by calculating the average sales amount per transaction. Here's how to achieve this:

Average_Sales_Per_Agent = 
AVERAGEX(
    Sales,
    Sales[SalesAmount]
)

Using Average_Sales_Per_Agent, the manager can quickly identify the average sales performance of each agent, facilitating better decision-making and performance reviews.

Conclusion

The AVERAGEX function is versatile and powerful for calculating averages based on complex expressions. These examples illustrate its application in various scenarios, such as simple averages, conditional averages, weighted averages, and averages of calculated columns.

For further learning, consider exploring courses on the Enterprise DNA Platform focused on advanced DAX functions and data modeling techniques. These resources can provide deeper insights and practical knowledge to enhance your data analysis skills.

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 AVERAGEX function in DAX computes the average of an evaluated expression across rows in a table. This guide covers its syntax, usage examples, and applications for calculating simple, conditional, and weighted averages effectively.