Forum Discussion

margaretaak's avatar
margaretaak
Frequent Visitor
9 months ago
Solved

Different Calculations

Why are the calculations in the Power BI visualization and in the DAX different? I use AVERAGE in the visualization and the result is 464252.5, I use AVERAGE in the DAX and the result is 12505.94. Ev...
  • rohit1991's avatar
    9 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.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