Calculation Issues

How to Display the Correct Total in Every Row Using DAX Measures in Excel

Natalie TaylorNatalie Taylor Nov 11, 2026 869 views

Question details

The user needs to create a DAX measure that correctly calculates and displays a total for each selected point ID row while maintaining accurate overall grand totals.

How to Display the Correct Total in Every Row Using DAX Measures
Product
Excel
Device & OS
not provided
Scenario
Writing complex DAX formulas in a Data Model where the default filter context causes totals to display incorrectly on individual detail rows or the grand total row.
Observed behavior
To accurately present the calculated total in every row, the measure must separate the evaluation logic for detail rows from the total rows using advanced conditional DAX logic.
Before you start

Ensure your dataset is added to the Excel Data Model (Power Pivot) and that you have basic familiarity with writing and applying DAX measures.

Solution 1Recommended

Use Conditional Logic to Handle Detail Rows and Totals Separately

This is the most robust method for displaying accurate totals, as it applies different calculation contexts depending on whether a single item or the grand total is being evaluated.

When using DAX, the grand total is not automatically a sum of the rows above it; it is evaluated in its own filter context. By combining HASONEVALUE, CALCULATE, and AVERAGEX within variables, you can force the Data Model to average the measure across the selected items properly.

1
Define the context check variable

Start your measure by defining a variable using the `HASONEVALUE` function (e.g., `VAR IsOneUtility = HASONEVALUE('Points'[Utility])`). This checks if the current row context is evaluating a single utility.

2
Calculate the individual row value

Create a second variable for the individual row calculation (e.g., `UtilityAverage`). Use the `CALCULATE` function combined with `ALL` or `ALLSELECTED` to remove the specific point filter so the rate calculates correctly for that item.

3
Calculate the grand total value

Create a third variable (e.g., `TotalAverage`) that uses `AVERAGEX` wrapped in `CALCULATE`. This iterates over the selected utilities and applies your base measure to find the correct total average.

4
Return the conditional result

End the measure with an `IF` statement: `RETURN IF(IsOneUtility, UtilityAverage, TotalAverage)`. This outputs the individual rate on data rows and the aggregated average on the grand total row.

Use Conditional Logic to Handle Detail Rows and Totals Separately
Context Tip: Because the `TotalAverage` variable uses `ALLSELECTED`, it successfully respects any outside slicer filters you have applied while ignoring the row context of the PivotTable itself.
Free Microsoft Office alternative

Looking for a Lightweight, Reliable Office Suite?

While advanced DAX data modeling (Power Pivot) is a feature exclusive to Microsoft Excel, WPS Office Spreadsheet provides a powerful, free alternative for everyday data analysis. With robust standard PivotTables, advanced formulas, and seamless format compatibility, WPS handles your daily reporting needs effortlessly without expensive subscriptions.

  1. 1. Download and Install: Get WPS Office for free from the official website and install it on your PC or Mac.
  2. 2. Open Your Excel File: Launch WPS Spreadsheet and seamlessly open your existing .xlsx workbooks.
  3. 3. Analyze with PivotTables: Select your data range, go to the Insert tab, and create a PivotTable to start analyzing your data immediately.
100% format compatibility with Microsoft Excel files (.xlsx, .xls, .csv).Built-in advanced PivotTable features for quick and effective data summarization.Lightweight installation with a familiar, easy-to-use interface for seamless migration.Completely free for standard daily office tasks and spreadsheet analysis.
microsoft office alternative - wps office

Frequently Asked Questions

What is the difference between ALL and ALLSELECTED in a DAX measure?

The ALL function completely removes any filters applied to the specified table or column, returning every possible row regardless of user selections. ALLSELECTED, however, removes the filters created by the current row or column context inside the visual (like a PivotTable row) but preserves explicit filters applied by the user, such as slicers or report-level filters.

Why does my DAX measure show the wrong grand total in a PivotTable?

In DAX, grand totals do not automatically add up the values of the rows displayed above them. Instead, the grand total evaluates the measure using the total filter context (where no individual row filters apply). To fix this, you often need to use iterating functions like SUMX or conditional logic (like HASONEVALUE) to force the total to aggregate correctly.

Can I use HASONEVALUE to check multiple columns at once?

No, HASONEVALUE evaluates only a single column and returns TRUE if exactly one distinct value is present in the current filter context. If you need to check multiple columns simultaneously, you must write multiple HASONEVALUE functions and combine them using logical operators like AND (&&).