Table of Contents
Use AVERAGE IF in Power BI (With Example)
1. The Necessity of Conditional Averaging in Data Analysis
In modern business intelligence, calculating simple averages often falls short of delivering meaningful insights. While standard aggregation functions provide a quick overview of a metric across an entire dataset, true analytical power is unlocked through conditional averaging. This process, often familiar to users of spreadsheet software as the AVERAGE IF function, allows analysts to determine the mean of a specific numerical column only for those rows that satisfy a predetermined logical condition. For instance, calculating the average transaction value exclusively for customers residing in a particular geographic region, or determining the mean production time only for products that passed quality inspection. This targeted calculation is fundamental for segmentation, performance benchmarking, and anomaly detection, guiding crucial business decisions based on filtered, precise data subsets.
When working within Power BI, the ability to perform these specific, criterion-based calculations is essential for generating dynamic reports and highly accurate measures. Although the standard suite of data analysis tools offers robust summation and averaging capabilities, achieving conditional results requires harnessing the expressive capabilities of Data Analysis Expressions (DAX). Unlike simpler environments where a single built-in function like AVERAGEIF() might handle this task directly, DAX demands a more structured, powerful approach. This structure involves combining fundamental DAX functions to manipulate the evaluation context, effectively instructing Power BI to look at the data under a specific set of rules before performing the final arithmetic operation. Understanding this contextual manipulation is the key to unlocking advanced analytical capabilities within the platform.
The core challenge for new Power BI users migrating from spreadsheet applications is recognizing that DAX operates differently—it is not cell-based, but column- and context-based. Therefore, instead of searching for a direct equivalent of AVERAGEIF, the expert approach involves constructing a robust formula that explicitly defines the filtering logic using core DAX engine concepts. The solution relies on the synergistic combination of two primary functions: CALCULATE, which modifies the evaluation context, and AVERAGE, the aggregation function applied after the modification. This methodology ensures that the calculations are performed efficiently and accurately, regardless of the size or complexity of the underlying data model.
2. DAX Syntax for Conditional Averaging: The CALCULATE and FILTER Pattern
Since DAX does not provide a native AVERAGEIF function, the standard and most reliable method for achieving conditional averages is by employing a pattern involving the CALCULATE function. The CALCULATE function is arguably the most powerful function in DAX, as it allows the expression provided as its first argument to be evaluated under a modified filter context, defined by the subsequent arguments. This capability is precisely what is needed to implement conditional logic: first, define the condition (the “IF” part), and then execute the aggregation (the “AVERAGE” part) within that constrained environment. By wrapping the AVERAGE function within CALCULATE, we instruct Power BI to perform the average calculation only after applying the filtering constraints we specify.
For scenarios involving the creation of a calculated column where the criteria depend on the value in the current row (row-by-row calculation), the implementation becomes slightly more complex, requiring the use of the FILTER function in conjunction with the EARLIER function. The FILTER function is used to reduce the number of rows over which the calculation is performed. When used inside CALCULATE, it applies temporary filtering to the entire table context. In our example, where we want the average points for a specific team to appear next to every player on that team, the FILTER function iterates over the entire data table and compares the current row’s team value (the external context) against the value from the row where the calculation originated (the internal context). This crucial step establishes the necessary row context transition required for the calculation.
The following syntax illustrates the robust and flexible pattern used in DAX to write an AVERAGE IF equivalent, specifically designed for calculating column values based on row context comparison:
You can use the following syntax in DAX to write an AVERAGE IF function in Power BI:
Avg Points =
CALCULATE (
AVERAGE ( 'my_data'[Points] ),
FILTER ( 'my_data', 'my_data'[Team] = EARLIER ( 'my_data'[Team] ) )
)
This particular formula creates a new column named Avg Points that contains the average value in the Points column for each unique value in the Team column in the table named my_data. This calculated column is exceedingly useful when you need to display or utilize the team-specific average alongside every individual player’s record, providing immediate context and facilitating ratio calculations or deviation analysis directly within the data table view. It demonstrates the sophisticated way DAX handles calculations that require referencing values outside the immediate row context.
3. Deconstructing the DAX Formula Components
To fully appreciate the mechanism behind the conditional average calculation, a detailed examination of each DAX component is necessary. The formula Avg Points = CALCULATE ( AVERAGE ( 'my_data'[Points] ), FILTER ( 'my_data', 'my_data'[Team] = EARLIER ( 'my_data'[Team] ) ) ) performs a highly specific contextual operation. It starts with CALCULATE, which is the foundational function that initiates a context transition, changing the row context inherited by the calculated column into a filter context that applies to the entire table evaluation. This transition is essential because aggregation functions like AVERAGE typically require a filter context to define the scope of data they operate on.
The first argument inside CALCULATE is AVERAGE ( 'my_data'[Points] ). This is the expression we want to evaluate. It calculates the average of the Points column. However, due to the CALCULATE wrapper, this average will not be applied to the entire table; instead, it will be applied only to the subset of rows defined by the subsequent filter argument. This ensures that the aggregation is only performed on data records that meet the specified condition, effectively implementing the “AVERAGE” part of the AVERAGE IF logic.
The core of the conditional logic lies within the second argument, which uses FILTER function ( 'my_data', 'my_data'[Team] = EARLIER ( 'my_data'[Team] ) ). The FILTER function iterates through the specified table ('my_data') and applies a boolean condition. The condition, 'my_data'[Team] = EARLIER ( 'my_data'[Team] ), is where the row context comparison takes place. The 'my_data'[Team] references the Team value in the row currently being iterated by the FILTER function. Conversely, the EARLIER function is critical here: it reaches back to retrieve the value of the Team column in the original, external row context where the calculated column formula was initiated. This comparison ensures that the filter context only includes rows where the Team value matches the team of the current player being processed, thereby isolating the data for that specific team before the average is calculated.
4. Example: Setting Up the Data Table in Power BI
To solidify the understanding of this powerful DAX pattern, let us walk through a practical scenario involving basketball player statistics. Suppose we have imported a simple dataset into Power BI that tracks various performance metrics, including the points scored by players across different teams. Our objective is to calculate the average points scored by each team and display that average alongside every player belonging to that respective team. This scenario perfectly mandates the use of context transition and conditional filtering achieved through the EARLIER function and its surrounding logic. The initial dataset, named my_data, contains essential columns such as Player Name, Team, and Points.
The structure of our hypothetical data table, my_data, is straightforward and representative of the data models used in many analytical projects. It contains multiple records for players, but the crucial aspect is the common attribute—the Team column—which serves as our grouping criteria for the conditional average calculation. We must ensure the calculation accurately segments the data based on this attribute. Visualizing the initial data helps in understanding the desired outcome: we expect the average derived for ‘Mavs’ players to be identical for all ‘Mavs’ rows, and similarly for ‘Rockets’ and ‘Spurs’ players, despite the overall table context containing mixed team data.
This is the sample table we will be working with:

Our goal is explicitly to create a new column, not a standard measure, because we need the resulting average value to be visible and usable at the row level. This enables comparison and further calculation where the team average acts as a baseline metric for each individual player. Using a calculated column necessitates the specific structure demonstrated previously to correctly handle row context transition.
5. Step-by-Step Implementation: Creating the Calculated Column
To begin the process of generating the conditional average, we must first navigate to the modeling tools within Power BI Desktop. Since we are adding a column to the existing table my_data, we need to utilize the dedicated feature for calculated columns. Start by clicking the Table tools tab located in the ribbon interface. This tab provides the necessary functionality for structural modifications and enhancements to the data model, including the creation of new calculated columns or measures.
Once in the Table tools menu, locate and click the New column icon. This action opens the formula bar, allowing us to input our custom DAX expression. It is essential to ensure that the active view is set to the data model view or the table view where the new column is intended to reside, ensuring the context for the calculation is correctly established for the my_data table.

Finally, we input the complete DAX formula into the formula bar. This formula, which integrates CALCULATE, AVERAGE, FILTER, and EARLIER, defines the logic for conditional averaging based on the team identity. Naming the column descriptively, such as Avg Points, ensures clarity in the final data model. The precision in typing this complex formula is critical, as any misplaced parentheses or quotation marks can lead to syntax errors.
Avg Points =
CALCULATE (
AVERAGE ( 'my_data'[Points] ),
FILTER ( 'my_data', 'my_data'[Team] = EARLIER ( 'my_data'[Team] ) )
)6. Analyzing the Resulting Calculated Column
Upon successful execution of the DAX formula, a new column named Avg Points will be appended to the my_data table. This column will display the calculated average points for the corresponding team on every row. The outcome visually confirms that the CALCULATE function successfully transitioned the row context into a filter context, enabling the aggregation function to operate only on the filtered subset of rows where the team matches the current row’s team. This visualization is essential for verifying the accuracy of complex DAX logic.
The resulting table clearly demonstrates the power of conditional logic in Power BI. Instead of calculating a single global average, the calculation is intelligently segmented by the ‘Team’ criterion. For every player, their team’s average point total is displayed, providing instant insight into how individual performance compares to their team’s baseline. This calculated column is now available for use in visuals, reports, and further measures within the Power BI data model, significantly enhancing the analytical utility of the dataset.

From the output, we can easily verify the conditional averages established by the DAX expression, grouped by the team classification:
- The average points value for players on the Mavs team is 18.75, calculated across four players (30, 15, 10, 20).
- The average points value for players on the Rockets team is 24, based on scores of 28 and 20.
- The average points value for players on the Spurs team is 21.67, derived from scores of 25, 22, and 18.
- The average points value for players on the Hornets team is 15.5, calculated from scores of 12 and 19.
7. Alternative Approach: Utilizing AVERAGEX for Conditional Measures
While the CALCULATE(AVERAGE(...), FILTER(...)) pattern is excellent for creating calculated columns based on row context, analysts often prefer creating measures, especially when the conditional average is intended for use in visualizations or slicers where the filter context is dynamically applied. For dynamic measures, an alternative and often cleaner approach is utilizing the AVERAGEX function. AVERAGEX is an iterator function in DAX that iterates over a table, evaluates an expression for each row, and then calculates the average of the resulting expressions.
The elegance of AVERAGEX in conditional averaging lies in its ability to handle the “IF” condition directly within the expression argument, typically using the IF function. For example, to calculate the average points for ‘Rockets’ across the entire report canvas, you could write a measure using the following structure: Avg Rockets Points = AVERAGEX ( 'my_data', IF ( 'my_data'[Team] = "Rockets", 'my_data'[Points], BLANK() ) ). By returning BLANK() for rows that do not meet the condition, AVERAGEX effectively ignores them in the averaging process, achieving the conditional result without needing external FILTER or CALCULATE functions, provided the condition is simple and constant.
However, for dynamic, column-level conditional averages (like the example we executed), the CALCULATE pattern remains the standard for calculated columns. When working with complex, variable criteria or when needing to override existing filter contexts, the explicit control offered by CALCULATE is indispensable. Choosing between CALCULATE/FILTER and AVERAGEX depends entirely on whether the requirement is a static calculated column or a dynamic measure responding to report filters.
8. Performance Considerations and Context Transition Deep Dive
Understanding the performance implications of complex DAX formulas, especially those involving iteration like the combination of CALCULATE, FILTER, and EARLIER function in a calculated column, is essential for professional data modeling in Power BI. Calculated columns are computed during data refresh and storage, meaning the calculation runs once for every single row in the table. If the table is large, running a resource-intensive formula that involves scanning the entire table repeatedly (as the FILTER function does) can significantly impact refresh times and model performance.
The inclusion of EARLIER often signifies a potentially costly operation in large datasets. The EARLIER function is necessary when the calculation depends on the value of the current row being processed, forcing DAX to handle the external row context reference. While effective, analysts should be mindful that such constructions generate significant overhead compared to simple aggregations or measures where the context is inherited from the report visual. For optimization, conditional averages should ideally be implemented as measures whenever possible, leveraging the report’s natural filter context to segment the data dynamically, thereby avoiding expensive row-by-row iteration during data load.
If the conditional average calculation must reside in a calculated column for subsequent row-level computations, ensuring the data model is highly optimized, perhaps by aggregating data beforehand or ensuring the filter criteria are highly selective, is crucial. Mastering the subtle differences between row context and filter context—and how CALCULATE bridges them—is the hallmark of advanced DAX proficiency. The implementation demonstrated here is technically robust but should be applied judiciously, favoring measures for large-scale, ad-hoc analysis and calculated columns only when the result is strictly needed at the atomic row level.
9. Conclusion: Mastering Conditional Logic for Robust Analysis
While Power BI does not feature a direct AVERAGEIF function, the robust functionality of DAX provides multiple powerful pathways to achieve conditional averaging. The combination of the CALCULATE function and the FILTER function, often augmented by EARLIER for calculated columns, serves as the definitive method for implementing complex, criteria-based aggregations. This pattern not only fulfills the basic requirement of conditional averaging but also offers flexibility to handle intricate filtering scenarios far beyond what a simple single-function equivalent could manage.
The ability to manipulate context is foundational to advanced data analysis in Power BI. By understanding how CALCULATE modifies filters and how functions like FILTER and EARLIER interact across row and filter contexts, users gain the expertise to solve nearly any complex analytical challenge. Whether calculating team-specific averages, analyzing sales based on specific product lines, or determining performance metrics under controlled conditions, the principles outlined above provide a clear, structured framework for highly accurate data segmentation and reporting.
Note: You can find the complete documentation for the AVERAGE function in Power BI. Understanding the entire family of DAX aggregation and context manipulation functions is key to transitioning from a report consumer to a sophisticated data modeler.
The following tutorials explain how to perform other common tasks in Power BI:
Cite this article
stats writer (2026). How to Calculate Conditional Averages in Power BI with AVERAGEIF. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/can-i-use-the-average-if-function-in-power-bi-if-so-could-you-provide-an-example/
stats writer. "How to Calculate Conditional Averages in Power BI with AVERAGEIF." PSYCHOLOGICAL SCALES, 28 Jan. 2026, https://scales.arabpsychology.com/stats/can-i-use-the-average-if-function-in-power-bi-if-so-could-you-provide-an-example/.
stats writer. "How to Calculate Conditional Averages in Power BI with AVERAGEIF." PSYCHOLOGICAL SCALES, 2026. https://scales.arabpsychology.com/stats/can-i-use-the-average-if-function-in-power-bi-if-so-could-you-provide-an-example/.
stats writer (2026) 'How to Calculate Conditional Averages in Power BI with AVERAGEIF', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/can-i-use-the-average-if-function-in-power-bi-if-so-could-you-provide-an-example/.
[1] stats writer, "How to Calculate Conditional Averages in Power BI with AVERAGEIF," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, January, 2026.
stats writer. How to Calculate Conditional Averages in Power BI with AVERAGEIF. PSYCHOLOGICAL SCALES. 2026;vol(issue):pages.
