Learn How to Calculate Conditional Averages in Power BI Using DAX


While Excel provides the straightforward `AVERAGEIF` function for calculating conditional averages, Power BI requires a more sophisticated approach using Data Analysis Expressions (DAX). This method leverages key functions to implement conditional logic based on row context. The following syntax demonstrates how to write the equivalent of an AVERAGE IF function in DAX, designed specifically for creating a calculated column that evaluates conditions across rows:

Avg Points =
CALCULATE (
    AVERAGE ( 'my_data'[Points] ),
    FILTER ( 'my_data', 'my_data'[Team] = EARLIER ( 'my_data'[Team] ) )
)

Understanding the Need for Conditional Aggregation in Power BI

When working within Power BI, performing conditional aggregation often involves calculating a metric for a subset of data that meets specific criteria. Unlike standard measures that aggregate data based on the current visual or report-level filter context, creating an average that is conditional upon values within the same row (such as finding the average points for the team associated with the current row) requires defining a new context. This is essential when we need the resulting average to appear alongside every individual record in a table view, allowing for direct comparison between an individual player’s performance and their team’s average performance.

The core challenge lies in shifting the context of calculation. A simple `AVERAGE(‘my_data'[Points])` would return the grand average of all points across the entire dataset. To replicate the functionality of AVERAGE IF, we must enforce a secondary filter context during the calculation. This filter must identify the current row’s grouping criterion (in this case, the `Team`) and then apply that criterion to the entire table before performing the average calculation. This complex interaction between row context and filter context is managed entirely through the elegant and powerful structure of the DAX formula presented above.

The formula creates a new calculated column named Avg Points. This column is populated by calculating the average value in the Points column, but this average is strictly constrained to records where the Team value matches the team of the current row being evaluated. This calculated column is fundamental for comparative analysis, cohort analysis, and other advanced data modeling tasks within your Power BI environment.

Deconstructing the Core DAX Formula

The conditional aggregation formula relies on three crucial DAX functions working in tandem: CALCULATE, AVERAGE, and EARLIER. Understanding the role of each function is key to mastering conditional logic in Power BI. The overall structure is: `CALCULATE ( [Aggregation Expression], [Filter Condition] )`.

The CALCULATE function is arguably the most powerful function in DAX. It modifies the existing filter context under which data is evaluated. In this instance, we instruct CALCULATE to perform the AVERAGE operation, but only after applying a specific filter condition defined by the second argument. This effectively transitions the operation from the current row context into a modified filter context, allowing the aggregation to be performed across the filtered group of rows rather than just the single row being evaluated.

The filter condition itself is defined using the FILTER function. The structure `FILTER ( ‘my_data’, ‘my_data'[Team] = EARLIER ( ‘my_data'[Team] ) )` iterates over the entire `my_data` table. The critical component here is the EARLIER function. When creating a calculated column, DAX processes the calculation row by row (known as row context). EARLIER captures the value of `[Team]` from the outer, currently evaluated row context, allowing that value to be used as a stable reference point inside the iterating FILTER function. In essence, it tells the calculation: “Find all rows where the Team column matches the Team value of the row I am currently calculating.” This mechanism successfully replicates the conditional logic of an AVERAGE IF operation.

Practical Example: Calculating Team Averages

To fully illustrate how this powerful DAX formula works, let us walk through a concrete scenario involving sports data. Suppose we have imported a dataset into Power BI named my_data, which contains records detailing individual basketball players, including their names, their respective teams, and the points they have scored over a period. This table is structured to show individual performance, but our goal is to contextualize that performance by calculating the average points scored by every player’s team.

The initial table, my_data, provides the raw inputs necessary for our conditional aggregation. Note the presence of multiple players belonging to the same team (e.g., ‘Mavs’ appears four times), which is precisely what allows us to define and calculate a meaningful team-level average.

Our objective is to augment this table by creating a new column that will display the group average—the average points scored by all players within a specific team—next to each player’s individual record. This necessitates using the DAX technique described earlier to ensure that when the formula is calculated for Player A (who is on the Mavs), it aggregates the points only from the Mavs players, and when it moves to Player B (who is on the Rockets), it aggregates only the points from the Rockets players.

Step-by-Step Implementation in Power BI Desktop

Implementing the AVERAGE IF logic requires utilizing the calculated column feature within Power BI Desktop. A calculated column is necessary here because the result needs to be stored within the data model, evaluated row-by-row, and used in filtering or sorting operations alongside the original data.

To begin the process, navigate to the Table tools ribbon in Power BI Desktop while viewing the data table. Within this tab, locate and click the New column icon. This action opens the formula bar, where we will input our complex DAX expression. This interface is specifically designed for authoring calculated columns and measures.

Once the formula bar is active, carefully type or paste the following DAX expression. This formula instructs CALCULATE to average the points, subject to the condition that the team in the outer row context (captured by EARLIER) matches the team in the inner iteration (performed by FILTER).

Avg Points =
CALCULATE (
    AVERAGE ( 'my_data'[Points] ),
    FILTER ( 'my_data', 'my_data'[Team] = EARLIER ( 'my_data'[Team] ) )
)

After confirming the formula by pressing Enter, Power BI will process the calculation row by row across the entire table. This results in the creation of a new column named Avg Points. This column successfully implements the desired conditional aggregation, displaying the calculated average points for the corresponding team next to every individual player record.

Interpreting the Calculated Result

Upon successful execution of the DAX formula, the my_data table is updated with the new Avg Points column, providing immediate insights into team performance relative to individual scores. The result confirms that the conditional logic successfully grouped the records based on the Team column before calculating the average of the Points column for that specific group.

Power BI AVERAGE IF

Analyzing the output confirms the accuracy of the conditional averaging:

  • The average points value for players on the Mavs team is 18.75 (calculated as (14 + 20 + 25 + 16) / 4).
  • The average points value for players on the Rockets team is 24 (calculated as (22 + 26) / 2).
  • The average points value for players on the Spurs team is approximately 21.67 (calculated as (18 + 24 + 23) / 3).
  • The average points value for players on the Hornets team is 15.5 (calculated as (13 + 18) / 2).

This calculated column is now available for use in reports, visualizations, and further DAX calculations, enabling detailed performance analysis where individual data points are contextualized by their group average. It is important to remember that this technique is required when the conditional average must exist as a static column in the data model, evaluated once upon data refresh.

Further Resources for DAX Mastery

Mastering conditional logic in DAX is fundamental for advanced data modeling in Power BI. While we focused on the AVERAGE IF equivalent here, the underlying principles of context transition and iteration apply to many other complex scenarios.

For users looking to deepen their knowledge, reviewing the official documentation for the key functions utilized is highly recommended:

  • The CALCULATE function documentation, which details how context transition works.
  • The AVERAGE function documentation, outlining standard aggregation behavior.
  • The EARLIER function documentation, which is crucial for understanding row context referencing.

The following tutorials explain how to perform other common tasks in Power BI, leveraging similar powerful DAX concepts:

Cite this article

Mohammed looti (2025). Learn How to Calculate Conditional Averages in Power BI Using DAX. PSYCHOLOGICAL STATISTICS. Retrieved from https://statistics.arabpsychology.com/use-average-if-in-power-bi-with-example/

Mohammed looti. "Learn How to Calculate Conditional Averages in Power BI Using DAX." PSYCHOLOGICAL STATISTICS, 12 Nov. 2025, https://statistics.arabpsychology.com/use-average-if-in-power-bi-with-example/.

Mohammed looti. "Learn How to Calculate Conditional Averages in Power BI Using DAX." PSYCHOLOGICAL STATISTICS, 2025. https://statistics.arabpsychology.com/use-average-if-in-power-bi-with-example/.

Mohammed looti (2025) 'Learn How to Calculate Conditional Averages in Power BI Using DAX', PSYCHOLOGICAL STATISTICS. Available at: https://statistics.arabpsychology.com/use-average-if-in-power-bi-with-example/.

[1] Mohammed looti, "Learn How to Calculate Conditional Averages in Power BI Using DAX," PSYCHOLOGICAL STATISTICS, vol. X, no. Y, ص Z-Z, November, 2025.

Mohammed looti. Learn How to Calculate Conditional Averages in Power BI Using DAX. PSYCHOLOGICAL STATISTICS. 2025;vol(issue):pages.

Download Post (.PDF)
Scroll to Top