Power BI DISTINCTCOUNT Totals: Why Matrix Totals Differ from Row Sums

Power BI DISTINCTCOUNT matrix totals are not row sums: overlapping customers, BLANK handling, lakehouse grain, and when SUMX is correct, with DAX examples.

Power BI DISTINCTCOUNT Totals: Why Matrix Totals Differ from Row Sums

Author: jackey.ye | Updated: 2026-11-26

A DISTINCTCOUNT matrix total is evaluated once over the total's own filter context, so it counts each customer once across all groups instead of adding the per-group distinct counts. This tutorial for data engineers and analytics architects in Singapore and the United States covers non-additive totals, overlapping sets, BLANK handling, and the narrow case where SUMX over VALUES is the intended measure, using a hand-checkable sample with DAX and expected results.

What Does a DISTINCTCOUNT Matrix Total Actually Compute?

The total is a separate evaluation of the measure over the total's filter context, not an aggregation of the visible row values. Microsoft's matrix documentation states that by default the total row shows the result of evaluating the field across the entire filter context of the report page. So the grand total cell runs DISTINCTCOUNT(Sales[CustomerKey]) against every row the page filters allow, and the row cells run the same measure against narrower contexts.

That is why DISTINCTCOUNT is non-additive: it counts distinct values in a column, and a value's distinctness depends on which rows are in scope. A customer who bought in both the Singapore and US regions is one distinct value in the total's context but appears as one distinct value in each region's context. Add the two region cells and that customer is counted twice; the total counts them once. Nothing is subtracted or lost — the total simply answers a different question than the sum of the cells.

Why Is the Grand Total Smaller Than the Sum of the Row Values?

The grand total is smaller because the same entity can appear in several groups, so summing group-level distinct counts double-counts it while the total counts it once. Microsoft's DISTINCTCOUNT page documents three scopes that map directly onto a matrix with row and column headers: category values count distinct orders within that specific category only; row totals count distinct orders across all categories for that year, each order once regardless of how many categories it appears in; and the grand total counts distinct orders across the entire dataset.

The page's own illustration makes the gap concrete. For 2005 it reports a grand total of 366 against 927 obtained by summing Accessories (135) + Bikes (345) + Clothing (242) + Components (205). That is an attributed example from Microsoft's sample model, not a figure from this article's dataset. The general rule follows: whenever groups overlap, total ≤ sum of parts, and the two are equal only when the sets are disjoint. This is documented, expected behavior, not a defect in the visual or the measure.

How Do Overlapping Customer Sets Break Additivity?

Overlap breaks additivity because the gap between the row sum and the total equals the overlap counted twice. For two groups, |A ∪ B| = |A| + |B| − |A ∩ B|: the total is the union, the row sum is |A| + |B|, and the difference is exactly |A ∩ B|. Extend that to n groups and the gap becomes the sum of all pairwise and higher-order overlaps, which is why the discrepancy rarely looks like a clean number.

In a real model the overlap is not a constant. It depends on the filter context — date range, region, channel, product line — so the "missing" amount changes as slicers change, and a reconciliation that balances in one view can fail in the next. The practical consequence: a finance or operations stakeholder who adds up the visible cells will get a different number from the total, and for the question "how many distinct customers in this scope," the total is the correct one.

What Is the Deterministic Sample and What Are the Hand-Derived Expected Results?

The sample below is an illustrative dataset, not observed production data. It has eight order rows, three customers, and two regions, with customer C2 deliberately active in both regions so the overlap is visible.

The sample model is a single fact table. All measures in this article reference Sales, a table with the columns OrderKey, CustomerKey, Region, and Amount. Sales[Region] is a plain text column stored on the fact table; there is no separate Region dimension in the sample and no relationship to define. Every DAX expression below uses Sales[Region] for exactly this reason — so SUMX ( VALUES ( Sales[Region] ), [Distinct Customers] ) iterates the two region values present in the fact table.

OrderKey

CustomerKey

Region

Amount

O1

C1

Singapore

100

O2

C1

Singapore

250

O3

C2

Singapore

400

O4

C2

United States

150

O5

C3

United States

300

O6

C3

United States

120

O7

C2

United States

220

O8

C1

Singapore

90

Illustrative sample (not observed production data): eight order rows, three customers, two regions. C2 appears in both regions, so the region-level distinct counts (2 + 2 = 4) exceed the distinct customers across the whole table (3). The gap of 1 is exactly the overlap {C2}.

Hand-derive the counts before touching Power BI. Distinct customers by region: Singapore has {C1, C2} = 2; United States has {C2, C3} = 2. Sum of region-level distinct customers = 4. Distinct customers across the whole table: {C1, C2, C3} = 3. The gap of 1 is C2, counted in both regions and once in the total. Distinct orders per customer: C1 has {O1, O2, O8} = 3; C2 has {O3, O4, O7} = 3; C3 has {O5, O6} = 2. Distinct orders overall = 8, and here the per-customer counts do sum to 8 because each order belongs to exactly one customer — a useful contrast showing that additivity depends on whether the grouping column partitions the key. Row count is also 8, since no order key repeats.

Example configuration — validate in your target environment.

Which DAX Measures Produce Which Totals?

Three measures cover the cases: the base exact count, the blank-excluding variant, and the deliberate row-sum reproduction. Against the sample, the base measure returns 2 / 2 in the region rows and 3 in the total; the SUMX variant returns 2 / 2 and 4 in the total.

Distinct Customers = DISTINCTCOUNT ( Sales[CustomerKey] )
  
  Distinct Customers NOBLANK = DISTINCTCOUNTNOBLANK ( Sales[CustomerKey] )
  
  Sum of Group Distinct =
  SUMX ( VALUES ( Sales[Region] ), [Distinct Customers] )
  

DISTINCTCOUNT counts distinct values in the column and, per Microsoft's reference, returns BLANK when it finds no rows to count. Its matrix total is 3 — the union of customers — and the row values are 2 and 2. DISTINCTCOUNTNOBLANK behaves identically on this sample because no customer key is blank; it diverges only once blanks exist, as the next section shows.

SUMX is an iterator: it evaluates the expression for each row of the table it is given and sums the results, per the SUMX reference. VALUES returns a one-column table of distinct values from the specified column, affected by the current filter context, per the VALUES reference. Together they iterate the two regions and sum 2 + 2 = 4, which is why the total matches the row sum by construction.

If your production model stores region in a separate dimension — say Region[Region] related to Sales[RegionKey] — then the measure must iterate that dimension's column instead: SUMX ( VALUES ( Region[Region] ), [Distinct Customers] ). Two conditions have to hold for the result to be right. First, the relationship between Sales and Region must exist, be active, and have a single-direction filter from the dimension to the fact table. Second, the measure must reference the same column the matrix groups on, or the iterator and the row header will disagree. Pick one design and keep it: either the flat Sales[Region] column used throughout this article, or a proper Region dimension with the relationship documented. Mixing the two is how you get a total that matches nothing on the page.

That construction is correct only when the business definition is sum of per-group distinct counts — for example, summing regional headcounts where a person may legitimately be counted in each region they work. When the question is "how many distinct customers in total," the same measure is a semantic error: it reports 4 for a population of 3. Choose the measure from the business question, not from which total looks tidier.

Example configuration — validate in your target environment.

How Does BLANK Affect DISTINCTCOUNT Totals?

DISTINCTCOUNT counts BLANK as a distinct value; DISTINCTCOUNTNOBLANK does not. Microsoft's DISTINCTCOUNTNOBLANK reference shows the difference directly: on DimProduct[EndDate] the two functions return 2 and 3 respectively, because one value in that column is blank.

In a matrix this has two effects. A blank member can appear as an extra row or column, and it adds one to any total whose scope includes it — so the total can exceed the number of identifiable customers by exactly one. The divergence often hides at row level: if no blank falls inside a particular region's filter, that region's cell reads the same under both measures while the grand total differs, which makes the total look wrong rather than differently defined.

VALUES adds a related wrinkle. When a relationship violates referential integrity, VALUES returns the distinct values plus a blank row, and fact rows with no matching dimension member are matched to that unknown member. Iterating VALUES inside SUMX therefore adds a blank group to the row sum, so the SUMX total can exceed even the sum of the visible cells. Decide explicitly whether unknown members belong in the count, then apply that decision consistently to the measure, the visual, and the reconciliation note.

How Do Lakehouse Grain and Deduplication Change the Number a Matrix Reports?

A DISTINCTCOUNT total is only as trustworthy as the grain of the table it counts. Start by separating three failure modes, because teams routinely conflate them.

Exact duplicate fact rows change neither number. If a load writes the same row twice — identical OrderKey, CustomerKey, and Region — then DISTINCTCOUNT(Sales[CustomerKey]) is unchanged, since the key still collapses to one value. The SUMX-over-VALUES total is also unchanged: the set of region values in the fact table is the same, and the inner DISTINCTCOUNT for each region still sees the same customer keys. This is a subtle but important point — duplicating rows does not manufacture overlap, so the "sum of per-group distinct counts" stays where it was.

What duplicates do change is row-level arithmetic. COUNTROWS doubles, and any SUM of a measure like Amount doubles too. That is a distinctly different symptom: additive measures inflate while distinct counts hold steady, which is a reliable tell that you have duplicate loads rather than a bad DAX measure.

Changed group membership and non-unique entity keys are separate problems. If a customer's Region value is reclassified, or a customer legitimately appears in more than one region, the per-region distinct counts move and so does the SUMX total — but that reflects the data, not duplication. Worse is a key that is not unique at its claimed grain, where one "customer" is really several entities sharing an identifier; distinct counts then disagree with the business definition and no DAX rewrite repairs that.

Verify uniqueness upstream, deduplicate in staging, and document the key before trusting any total. For the model-side view of the same problem, see DAX performance optimization for lakehouse models.

What Is the Numbered Engineering Workflow to Validate a DISTINCTCOUNT Total?

Run these eight steps in order against a scratch copy of the model. Each step has a checkpoint and an expected result, so a failure stops the workflow at the layer that caused it rather than at the visual. Example configuration — validate in your target environment.

  1. Confirm grain and key uniqueness upstream. Query the fact table for duplicate keys at the claimed grain. Checkpoint: zero duplicate rows for the key column. Expected result: a documented grain statement you can cite in the report.

  2. Build the scratch sample and reproduce the hand-derived totals. Load the eight-row sample from the previous section. Checkpoint: region counts 2 and 2, grand total 3, row sum 4.

  3. Add the base DISTINCTCOUNT measure and compare row values with the total. Checkpoint: the matrix total reads 3 while the two region cells read 2 and 2.

  4. Add the SUMX-over-VALUES variant and confirm it equals the row sum. Checkpoint: the variant returns 4 at the total, matching 2 + 2.

  5. Decide the business definition and pick the measure. Checkpoint: a written statement of whether the question is "distinct customers overall" (DISTINCTCOUNT) or "sum of per-region distinct counts" (SUMX over VALUES).

  6. Test BLANK handling with DISTINCTCOUNTNOBLANK. Add a row with a blank CustomerKey. Checkpoint: DISTINCTCOUNT rises by one, DISTINCTCOUNTNOBLANK does not.

  7. Re-check under slicer changes. Apply a date slicer and confirm the total still equals the distinct count for the filtered scope, not the sum of visible cells. Where date filters are interpreted in local time, test with named zones such as SGT (UTC+8) and US Eastern Time (UTC−5 or UTC−4 under daylight saving) so a boundary order does not silently move between periods.

  8. Document the chosen measure and expected total. Checkpoint: the report page or model documentation names the measure, its expected total for the sample, and the BLANK policy.

What Are the Prerequisites and Version Considerations?

You need Power BI Desktop with permission to edit measures, a semantic model whose key column is defined and documented, and a scratch file in which to reproduce the sample. The behavior described here was checked against Microsoft's DAX and matrix documentation on 2026-11-26; function availability and preview status change, so re-check the linked pages before you standardize on a function.

Three limitations matter for totals. DISTINCTCOUNT and DISTINCTCOUNTNOBLANK are not supported in DirectQuery mode when used in calculated columns or row-level security rules. APPROXIMATEDISTINCTCOUNT returns an estimate; Microsoft's reference documents an error rate of roughly 1.6% for Import and Direct Lake models and notes that support in those storage modes is currently in preview, so it is not a drop-in replacement when exact totals are required. Storage mode also affects cost: DirectQuery documentation notes that totals and subtotals, especially with DistinctCount, can add extra queries or degrade performance, while Direct Lake and Import queries are processed by the VertiPaq engine and normally outperform DirectQuery for visual interaction.

Comparison: DISTINCTCOUNT, DISTINCTCOUNTNOBLANK, SUMX over VALUES, and APPROXIMATEDISTINCTCOUNT

Measure

What it counts

BLANK included?

Total additive?

Intended use

Main limitation

DISTINCTCOUNT

Distinct values in a column

Yes

No

Exact distinct count over the total's filter context

Not supported in DirectQuery for calculated columns or RLS

DISTINCTCOUNTNOBLANK

Distinct non-blank values

No

No

Exact count when unknown members must be excluded

Same DirectQuery restriction as DISTINCTCOUNT

SUMX over VALUES

Sum of per-group distinct counts

Depends on inner measure

Yes, by construction

Only when "sum of groups" is the business definition

Double-counts overlapping entities; wrong for a true total

APPROXIMATEDISTINCTCOUNT

Estimated distinct values

Yes

No

High-cardinality columns where an estimate is acceptable

Approximate; Microsoft documents ~1.6% error for Import and Direct Lake, both still in preview

Read the table by business definition first: if the question is "how many distinct customers in total," only the two exact DISTINCTCOUNT variants answer it, and neither produces an additive total. Then filter by exactness and storage mode — APPROXIMATEDISTINCTCOUNT trades accuracy for high-cardinality scale, and SUMX over VALUES is a deliberate choice to report a sum of groups rather than a true distinct total.

Reusable Checklist and Asset

Paste this checklist into the review record for any report that shows a distinct count in a matrix.

  • Grain and key uniqueness confirmed upstream, with the grain statement documented

  • Scratch sample reproduced and hand-derived totals matched (2, 2, total 3, row sum 4)

  • Base DISTINCTCOUNT measure and SUMX-over-VALUES variant both tested

  • BLANK policy decided and recorded (DISTINCTCOUNT or DISTINCTCOUNTNOBLANK)

  • Storage mode and DirectQuery limitations checked for calculated columns and RLS

  • Slicer behavior verified, including date boundaries in SGT and US Eastern Time

  • Chosen measure and expected total written into the report or model documentation

Example configuration — validate in your target environment. The SQL deduplicates at the order-customer grain; the DAX defines the three measures used above.

-- Deduplicate at the declared grain: one row per order and customer
  WITH ranked AS (
    SELECT
      order_id,
      customer_key,
      region,
      order_ts,
      ROW_NUMBER() OVER (
        PARTITION BY order_id, customer_key
        ORDER BY order_ts DESC
      ) AS rn
    FROM staging.sales_orders
  )
  SELECT order_id, customer_key, region, order_ts
  FROM ranked
  WHERE rn = 1;
  
Distinct Customers = DISTINCTCOUNT ( Sales[CustomerKey] )
  
  Distinct Customers NOBLANK = DISTINCTCOUNTNOBLANK ( Sales[CustomerKey] )
  
  Sum of Group Distinct =
  SUMX ( VALUES ( Sales[Region] ), [Distinct Customers] )
  

Against the sample, Distinct Customers returns 2 and 2 by region with a total of 3, Sum of Group Distinct returns 4 at the total, and Distinct Customers NOBLANK returns the same values until a blank key is introduced. The same total-in-context rule applies to time-intelligence items; see Power BI calculation groups and SELECTEDMEASURE for time intelligence for how totals are evaluated in the visual's filter context rather than summed from visible rows.

Frequently Asked Questions

Why does my Power BI matrix total not equal the sum of the DISTINCTCOUNT row values?

The total is evaluated once over the total's filter context and counts each entity once, while the row values count distinct entities within each group, so overlapping entities are counted in multiple rows but once in the total. This is expected non-additive behavior.

Does DISTINCTCOUNT count BLANK, and how does that change the total?

DISTINCTCOUNT counts BLANK as a distinct value; DISTINCTCOUNTNOBLANK excludes it. A BLANK bucket can add one to a total and appear as an extra group, so decide explicitly whether unknown members belong in the count.

When should I use SUMX over VALUES instead of DISTINCTCOUNT?

Use SUMX over VALUES only when the business definition is the sum of per-group distinct counts, such as summing regional headcounts where a person may legitimately appear in each region. For a true distinct total, use DISTINCTCOUNT.

How does lakehouse grain or duplicate rows affect the distinct count a matrix reports?

Exact duplicate fact rows change neither: with keys and group memberships unchanged, DISTINCTCOUNT and a sum of per-group distinct counts both return the same value. Duplicates do inflate COUNTROWS and SUM. Separately, changed group membership moves the per-group counts, and a key that is not unique at its claimed grain makes totals disagree with the business definition. Confirm grain and deduplicate upstream before trusting totals.

Is APPROXIMATEDISTINCTCOUNT a safe replacement for DISTINCTCOUNT in totals?

No. Microsoft's APPROXIMATEDISTINCTCOUNT reference documents an error rate of roughly 1.6% for Import and Direct Lake models, and support in those storage modes is currently in preview, so it is not a drop-in when exact totals are required. Use it only for high-cardinality columns where an estimate is acceptable.

Related Articles