live wire
▸EKOS submits 70.15% on BIRD’s hidden test and 88.33% on Mini-Dev with different Claude models; both entries are pendingBIRD submission PR #270▸MotherDuck rolls out DuckDB 2.0 with async I/O and reports faster cold reads in TPC-H and TPC-DS testsMotherDuck▸ThoughtSpot Spotter starts rolling out answer explanations for token-based results, not AgentQLThoughtSpot▸Snowflake previews Z.ai GLM 5.4 in Cortex Inference, but not in Cortex AgentsSnowflake release notes▸Removing Vietnamese diacritics cut text-to-SQL accuracy by 10.3–37.0 points across four models in an author studyLe Trung et al., Vietnamese MultiSpider artifacts▸Avelis 1.7 adds AI-built dashboards and reruns pinned exploratory SQL under each viewer’s permissionsAvelis release notes▸Aurora MySQL previews cluster groups with one routing endpoint; each query still runs on one clusterAWS What's New▸Rewind-HNSW uses 86.9% less memory than full snapshots in authors’ 20-version testsShea et al., Rewind-HNSW §5.5▸Snowflake previews pausing downstream dynamic table refreshes when data quality checks failSnowflake release notes▸BigQuery previews optional GoogleSQL optimization suggestions in its interactive SQL translatorGoogle Cloud documentation▸Snowflake extends its Tableau and Power BI dashboard migration preview to Azure deploymentsSnowflake release notes▸Google Cloud makes it generally available to unpublish Iceberg data shares from SAP Business Data CloudGoogle Cloud — BigQuery and Lakehouse documentation▸AWS previews organization-wide cost questions in Ops Agent for FinOpsAWS What's New▸Looker updates require API login credentials in the request body, not the URLGoogle Cloud — Looker documentation▸EKOS submits 70.15% on BIRD’s hidden test and 88.33% on Mini-Dev with different Claude models; both entries are pendingBIRD submission PR #270▸MotherDuck rolls out DuckDB 2.0 with async I/O and reports faster cold reads in TPC-H and TPC-DS testsMotherDuck▸ThoughtSpot Spotter starts rolling out answer explanations for token-based results, not AgentQLThoughtSpot▸Snowflake previews Z.ai GLM 5.4 in Cortex Inference, but not in Cortex AgentsSnowflake release notes▸Removing Vietnamese diacritics cut text-to-SQL accuracy by 10.3–37.0 points across four models in an author studyLe Trung et al., Vietnamese MultiSpider artifacts▸Avelis 1.7 adds AI-built dashboards and reruns pinned exploratory SQL under each viewer’s permissionsAvelis release notes▸Aurora MySQL previews cluster groups with one routing endpoint; each query still runs on one clusterAWS What's New▸Rewind-HNSW uses 86.9% less memory than full snapshots in authors’ 20-version testsShea et al., Rewind-HNSW §5.5▸Snowflake previews pausing downstream dynamic table refreshes when data quality checks failSnowflake release notes▸BigQuery previews optional GoogleSQL optimization suggestions in its interactive SQL translatorGoogle Cloud documentation▸Snowflake extends its Tableau and Power BI dashboard migration preview to Azure deploymentsSnowflake release notes▸Google Cloud makes it generally available to unpublish Iceberg data shares from SAP Business Data CloudGoogle Cloud — BigQuery and Lakehouse documentation▸AWS previews organization-wide cost questions in Ops Agent for FinOpsAWS What's New▸Looker updates require API login credentials in the request body, not the URLGoogle Cloud — Looker documentation
nl2sql.ai
guideSQL Guide

Why a pivot grand total for distinct customers is not the sum of its cells

Metabase’s engineering write-up shows how the database computes each subtotal separately. A three-row example gives analytics agents a test for double-counting.

By The News Desk· Nov 29, 2026the quick take — two AI hosts go live when you do

An analytics agent asked for “unique buyers by channel, plus the grand total” should not add the channel counts. A buyer who ordered through two channels belongs in both counts, but only once in the grand total. Metabase’s engineering write-up shows the distinction in the SQL: detail cells and totals are separate aggregations, even when the database returns them in one result.

Three rows are enough to test it

Suppose customer A bought through Web and Store, and customer B bought through Web. The Web cell is 2 and the Store cell is 1. Adding the cells gives 3, but the overall distinct count is 2. Neither channel cell needs to change to make the grand total correct. If the agent only receives those two counts, it cannot recover the answer: Web could have two customers and Store a third, which would make the total 3 with the same visible cells.

The following illustrative query applies the same grouping-set pattern to a distinct count. In PostgreSQL’s documented semantics, each grouping set aggregates the input independently. The empty set () groups all qualifying rows together; GROUPING(channel) distinguishes the grand-total row from a detail group whose channel is actually null.

WITH orders(channel, customer_id) AS (
  VALUES ('Web', 'A'), ('Store', 'A'), ('Web', 'B')
)
SELECT channel, GROUPING(channel) AS is_total,
       COUNT(DISTINCT customer_id) AS unique_buyers
FROM orders
GROUP BY GROUPING SETS ((channel), ());

Ask the engine for the total

Metabase’s engineering post describes how its version 64 native pivot path compiles the detail, subtotal and grand-total aggregations into one statement when the feature is enabled and the driver supports it. The setting was off by default in v64. The earlier path issued separate queries for those levels. The distinction matters regardless of which path runs: neither requires the grand total to be the sum of displayed cells. The Metabase pivot documentation also distinguishes a query-builder pivot from a native SQL question: if you start with a SQL question that has no parameters, save it first and build a query-builder question on top of it. For this metric, keep customer IDs in that input rather than saving only the channel counts.

For a text-to-SQL acceptance test, put one buyer in two groups and require the agent to explain why the grand total is lower than the sum. If it has only the displayed counts, the right response is to ask for the underlying rows or a separately computed total, not to guess how much the groups overlap.

Filed by The News Desk. Corrections: desk@nl2sql.ai · Our standards →

comments · 0

    Comments are moderated before they appear. Your email is used once to confirm it is you — never shown, never sold. Corrections and questions get an answer from the desk when we have one.