Pivot Table Issues

Sum Dynamic PivotTable Data by Type with Excel Data Model Measures

Ayan MasoodAyan Masood Dec 2, 2026 869 views

Question details

Summarize quantities by item type from dynamic SQL Server data without relying on fixed PivotTable cell references.

Sum Dynamic PivotTable Data by Type Using Excel Data Model Measures
Product
Microsoft Excel PivotTable and Data Model
Device & OS
not provided
Scenario
A PivotTable uses SQL Server data that can change after refresh, and the user needs totals for each lot or item type.
Observed behavior
Item types and counts can move to different cells after refreshes, making a fixed-cell COUNTIF formula unreliable.
Before you start

Check that the SQL Server data is loaded into the workbook's Data Model and identify the columns containing the item type and quantity. Confirm whether each row represents an item or whether a quantity column contains values to sum.

Solution 1Recommended

Create a PivotTable and DAX measure from the Data Model

Use a separate PivotTable to summarize each type without depending on the layout of the original report.

1
Insert a PivotTable

In Excel, select Insert > PivotTable and choose the option to use this workbook's Data Model. Place the new PivotTable on a new or existing worksheet.

2
Create a quantity measure

On the Power Pivot tab, choose Measures > New Measure. Name it Total Quantity and enter =SUM(Sales[Quantity]) as the formula, replacing Sales and Quantity with your actual table and column names.

3
Arrange the fields

In the PivotTable Fields pane, drag the lot or item type field to Rows and the Total Quantity measure to Values. Use the type field's filter if you only need selected types.

4
Refresh the report

Choose Data > Refresh All to update the SQL Server connection and PivotTables. Check that the new PivotTable displays the current totals by type.

Create a PivotTable and DAX measure from the Data Model
Count rows instead of summing quantities: If each source row represents one item, create a measure with =COUNTROWS(Sales) instead. Use SUM when a numeric quantity column stores the amounts to total.
Free Microsoft Office alternative

Explore PivotTable summaries in WPS Spreadsheets

WPS Office is a free, lightweight Office alternative with a familiar interface for working with spreadsheet reports. Open compatible Excel files and use PivotTables to summarize suitable data; Excel Data Model connections and DAX measures may not be supported.

Summarize suitable spreadsheet data by type with PivotTablesOpen and edit compatible Microsoft Excel XLSX filesWork in a familiar spreadsheet interface for easier migrationUse a free, lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

Why is a fixed-cell COUNTIF unreliable for this PivotTable?

After a refresh, types and counts can move to different cells as the PivotTable layout changes. A separate PivotTable groups the source data by type instead of relying on those cell positions.

Should I use SUM or COUNTROWS in my measure?

Use SUM on a numeric quantity column when rows contain quantities to total. Use COUNTROWS on the source table when each row represents one item to count.

How do I show only one lot type?

In the new PivotTable, use the filter on the lot type row field to select the type you want. The measure will show the total for the selected type.

How do I update the totals after the SQL Server data changes?

Choose Data > Refresh All in Excel to refresh the connection and PivotTables. Verify that the SQL Server connection is available and that the refreshed data contains the expected records.