Sum Dynamic PivotTable Data by Type with Excel Data Model Measures
Question details
Summarize quantities by item type from dynamic SQL Server data without relying on fixed PivotTable cell references.

- 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.
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.
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.
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.
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.
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.
Choose Data > Refresh All to update the SQL Server connection and PivotTables. Check that the new PivotTable displays the current totals by type.

Summarize quantity directly in a second PivotTable
Use the quantity field in Values when a simple sum is sufficient and you do not need a reusable DAX measure.
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.

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.




