Forum Discussion
Different Calculations
- 11 months ago
Hi margaretaak
This happens because Power BI visuals and DAX evaluate context differently.
When you drag a numeric field (e.g., Average of [Sales]) into a visual, Power BI averages all visible rows directly.
But when you use a DAX measure like:Row-based Average
Avg_Sales = AVERAGE('Table'[Sales])It averages within each filter or group in the visual ,not across all raw rows.
That’s why SUM gives identical results (it’s additive), but AVERAGE doesn’t ,it depends on the level of aggregation.
Context-based Average
Avg_Sales_ByCustomer = AVERAGEX( VALUES('Table'[Customer]), CALCULATE(SUM('Table'[Sales])) )In nut shell-The visual’s average is row-based, while your DAX measure is context-based. SUM matches; AVERAGE can differ because of grouping level.
For example:-
Sample data
1. Row-based Average-
This averages the Sales column over all visible rows in the current filter context.
If there are 3 rows (100, 300, 1000), it gives:
(100 + 300 + 1000) / 3 = 466.672. Context-based Average-
-
First, Power BI creates one row per Customer (A and B).
-
Then it calculates each customer’s total:
-
A → 100 + 300 = 400
-
B → 1000
-
-
Finally, it averages those totals: (400 + 1000) / 2 = 700
-
Hi margaretaak
This happens because Power BI visuals and DAX evaluate context differently.
When you drag a numeric field (e.g., Average of [Sales]) into a visual, Power BI averages all visible rows directly.
But when you use a DAX measure like:
Row-based Average
Avg_Sales = AVERAGE('Table'[Sales])
It averages within each filter or group in the visual ,not across all raw rows.
That’s why SUM gives identical results (it’s additive), but AVERAGE doesn’t ,it depends on the level of aggregation.
Context-based Average
Avg_Sales_ByCustomer =
AVERAGEX(
VALUES('Table'[Customer]),
CALCULATE(SUM('Table'[Sales]))
)
In nut shell-The visual’s average is row-based, while your DAX measure is context-based. SUM matches; AVERAGE can differ because of grouping level.
For example:-
Sample data
1. Row-based Average-
This averages the Sales column over all visible rows in the current filter context.
If there are 3 rows (100, 300, 1000), it gives:
(100 + 300 + 1000) / 3 = 466.67
2. Context-based Average-
-
First, Power BI creates one row per Customer (A and B).
-
Then it calculates each customer’s total:
-
A → 100 + 300 = 400
-
B → 1000
-
-
Finally, it averages those totals: (400 + 1000) / 2 = 700