---
title: DISTINCTCOUNT – นับจำนวนค่าเอกลักษณ์ในคอลัมน์
url: https://www.thepexcel.com/functions/dax/aggregation/distinctcount-dax/
type: function-explainer
program: DAX
syntax: "DISTINCTCOUNT(<column>)"
date: 2025-12-13
updated: 2025-12-21
scores:
  popularity: 8
  difficulty: 3
  usefulness: 8
---

# DISTINCTCOUNT – นับจำนวนค่าเอกลักษณ์ในคอลัมน์

> DISTINCTCOUNT นับจำนวนค่าที่แตกต่างกันทั้งหมดในคอลัมน์ รวมถึง BLANK values ถ้าไม่มีแถวข้อมูล จะคืนค่

## คำอธิบาย

DISTINCTCOUNT นับจำนวนค่าที่แตกต่างกันทั้งหมดในคอลัมน์ รวมถึง BLANK values ถ้าไม่มีแถวข้อมูล จะคืนค่า BLANK

## Syntax

```excel
DISTINCTCOUNT(&lt;column&gt;)
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| column | Yes | Column |  | คอลัมน์ที่ต้องการนับค่าเอกลักษณ์ (สามารถใช้ได้กับ data type ใดก็ได้ - number, text, date, etc.) |

## เคสการใช้งาน

### นับจำนวนลูกค้าที่มาใช้บริการ

นับจาก CustomerID ในตาราง Sales เพื่อดูว่ามีลูกค้าไม่ซ้ำกี่คน

_เหมาะกับ:_ customer-count

### นับจำนวน SKU ที่ขายได้

ดูความหลากหลายของสินค้าที่ขายออกไป

_เหมาะกับ:_ product-variety

## ตัวอย่าง

### 1. นับ customer ที่ซื้อสินค้า

```excel
Total Customers = DISTINCTCOUNT(Sales[CustomerID])
```

**ผลลัพธ์:** `15`

ถ้า Sales table มี 100 แถว แต่ customer ที่ต่างกันมี 15 คน DISTINCTCOUNT จะคืน 15 ไม่ใช่ 100

### 2. นับค่าเอกลักษณ์รวมถึง BLANK

```excel
Unique Categories = DISTINCTCOUNT(Products[SubCategory])
```

**ผลลัพธ์:** `3`

นับค่าเอกลักษณ์: "Electronics" (1), "Furniture" (1), BLANK (1) = รวม 3 ค่า (แม้ว่ามี BLANK 2 แถว แต่นับเป็น 1 ค่าเท่านั้น)

### 3. ใช้กับ FILTER เพื่อนับเฉพาะบาง category

```excel
Electronics Customers = 
VAR ElectronicsOrders = FILTER(Sales, Sales[Category] = "Electronics")
RETURN
    DISTINCTCOUNT(ElectronicsOrders[CustomerID])
```

**ผลลัพธ์:** `3`

FILTER ตรวจเลือกเฉพาะแถว Electronics (3 แถว: C001, C002, C004) แล้ว DISTINCTCOUNT นับ customer ที่แตกต่าง = 3

### 4. เปรียบเทียบ DISTINCTCOUNT vs DISTINCTCOUNTNOBLANK

```excel
With Blanks = DISTINCTCOUNT(Orders[Status])     → 4 (Completed, Pending, BLANK, Cancelled)

Without Blanks = DISTINCTCOUNTNOBLANK(Orders[Status]) → 3 (Completed, Pending, Cancelled)
```

**ผลลัพธ์:** `ด้วย BLANK = 4, ไม่มี BLANK = 3`

DISTINCTCOUNT นับ BLANK เป็นค่า 1 ค่า แต่ DISTINCTCOUNTNOBLANK ไม่นับ BLANK เลย ใช้ DISTINCTCOUNTNOBLANK เมื่อต้องการไม่สนใจค่าว่าง

## หมายเหตุเพิ่มเติม

- DISTINCTCOUNT ใช้กับ ID columns เช่น CustomerID, ProductID เพื่อนับ cardinality

- ถ้าต้องหลีกเลี่ยง BLANK ใน count ให้ใช้ DISTINCTCOUNTNOBLANK

- DISTINCTCOUNT = COUNTROWS(DISTINCT(column)) - สองวิธีเหมือนกัน แต่ DISTINCTCOUNT สั้นและเร็วกว่า

- ระวังการใช้ DISTINCTCOUNT ใน Pivot Table Totals เพราะผลอาจ double-count ได้

- ใช้ APPROXIMATEDISTINCTCOUNT บน Large tables เพื่อ performance ที่ดีขึ้น (trade-off with accuracy)

## คำถามที่พบบ่อย

**Q: ทำไม DISTINCTCOUNT นับ BLANK ด้วย**

DISTINCTCOUNT นับ BLANK ว่าเป็นค่า 1 ค่า เพราะ ใน DAX ค่าว่างถือเป็นค่าเอกลักษณ์หนึ่ง ถ้าต้องการไม่นับ BLANK ให้ใช้ DISTINCTCOUNTNOBLANK แทน

**Q: DISTINCTCOUNT กับ COUNT ต่างกันอย่างไร**

COUNT นับจำนวนแถว (non-blank) แต่ DISTINCTCOUNT นับจำนวนค่าที่แตกต่าง เช่น Customer C001 มี 5 order COUNT = 5, DISTINCTCOUNT = 1

**Q: DISTINCTCOUNT เทียบเท่ากับ COUNTROWS(DISTINCT()) หรือไม่**

ใช่ DISTINCTCOUNT(table[column]) เทียบเท่ากับ COUNTROWS(DISTINCT(table[column])) แต่ DISTINCTCOUNT ง่ายและเร็วกว่า

**Q: ใช้ DISTINCTCOUNT ได้หรือไม่เมื่อคำนวณใน Pivot Table**

ได้ แต่ระวังเรื่อง Totals ที่ double-count ได้ เช่น ถ้า Customer C001 ปรากฏในหลาย Product Category แล้วหาผลรวม total อาจไม่เท่ากับของจริง

## ฟังก์ชันที่เกี่ยวข้อง

- [DISTINCTCOUNTNOBLANK – นับจำนวนค่าที่ไม่ซ้ำ (ไม่รวม Blank)](https://www.thepexcel.com/functions/dax/aggregation/distinctcountnoblank-dax/)
- [APPROXIMATEDISTINCTCOUNT – นับจำนวนค่าไม่ซ้ำแบบประมาณ (เน้นความเร็ว)](https://www.thepexcel.com/functions/dax/aggregation/approximatedistinctcount-dax/)
- [COUNTROWS – นับจำนวนแถวในตารางและเทบิลเสมือน](https://www.thepexcel.com/functions/dax/aggregation/countrows-dax/)
- [DISTINCT – ดึงรายการที่ไม่ซ้ำ (Unique Values) พร้อมหลีกหนีค่า Blank Row](https://www.thepexcel.com/functions/dax/table-manipulation/distinct-dax/)
- [CALCULATE – ฟังก์ชันหลักของ DAX ที่ควบคุม Filter Context](https://www.thepexcel.com/functions/dax/filter/calculate-dax/)

## แหล่งข้อมูลเพิ่มเติม

- [DAX.guide: DISTINCTCOUNT](https://dax.guide/distinctcount/) _(guide)_
- [Microsoft Learn: DISTINCTCOUNT](https://learn.microsoft.com/en-us/dax/distinctcount-function-dax) _(official)_
- [SQLBI: DISTINCTCOUNT and Aggregation](https://www.sqlbi.com/articles/measure-the-cardinality-of-columns/) _(guide)_

---

_Source: [https://www.thepexcel.com/functions/dax/aggregation/distinctcount-dax/](https://www.thepexcel.com/functions/dax/aggregation/distinctcount-dax/)_
