---
title: CUSTOMDATA – ฟังก์ชัน DAX
url: https://www.thepexcel.com/functions/dax/information/customdata-dax/
type: function-explainer
program: DAX
syntax: CUSTOMDATA()
date: 2025-12-14
updated: 2025-12-17
scores:
  popularity: 3
  difficulty: 4
  usefulness: 3
---

# CUSTOMDATA – ฟังก์ชัน DAX

> ดึงข้อความ Custom Data จากการเชื่อมต่อปัจจุบัน

## คำอธิบาย

CUSTOMDATA ดึงข้อความ Custom Data ที่แนบมากับการเชื่อมต่อ (เช่นค่า user role, region, หรือ token จากแอป) เพื่อนำไปใช้ใน Measure หรือ RLS ช่วยสร้างเงื่อนไขตามบริบทผู้ใช้โดยไม่ต้องแก้โมเดล

## Syntax

```excel
CUSTOMDATA()
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| (none) | No | text | - | ไม่มีอาร์กิวเมนต์ เรียกใช้เพื่อตรวจสอบข้อความ Custom Data ที่แนบมากับการเชื่อมต่อ |

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: อ่านค่า Custom Data ที่ถูกส่งมาจากแอป

```excel
Session Label = CUSTOMDATA()
```

**ผลลัพธ์:** `ค่าข้อความที่แนบมากับการเชื่อมต่อ เช่น "premium-user"`

ใช้ดึงข้อความที่ฝังมากับคอนเนกชัน เพื่อใช้ปรับตรรกะหรือการแสดงผลตามสิทธิ์ของผู้ใช้

### 2. ตัวอย่างที่ 2: ใช้สร้างการแสดงผลแตกต่างตามสิทธิ์

```excel
User Tier = IF( CUSTOMDATA() = "premium", "Premium", "Standard" )
```

**ผลลัพธ์:** `"Premium" หรือ "Standard"`

อ่านค่า Custom Data แล้วแสดงระดับผู้ใช้ตามข้อความที่แนบมา เหมาะกับการปรับ UI หรือ KPI เฉพาะกลุ่ม

### 3. ตัวอย่างที่ 3: ใช้ใน RLS หรือการกรองแบบมีเงื่อนไข

```excel
Sales (Custom Region) = 
CALCULATE(
    [Total Sales],
    Customers[Region] = CUSTOMDATA()
)
```

**ผลลัพธ์:** `ยอดขายเฉพาะ Region ที่ตรงกับค่า Custom Data`

CALCULATE ใช้ CUSTOMDATA เป็นตัวกรอง region เพื่อให้ผู้ใช้แต่ละคนเห็นเฉพาะข้อมูลที่ตรงกับสิทธิ์หรือค่าที่ถูกส่งเข้ามา

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

ใช้สำหรับส่งค่าบริบทจากแอปภายนอกหรือ DirectQuery มายังโมเดล ช่วยทำเงื่อนไข RLS หรือปรับผลลัพธ์ตามผู้ใช้ได้ยืดหยุ่น

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

**Q: ฟังก์ชันนี้ใช้สำหรับอะไร**

CUSTOMDATA ใช้สำหรับการวิเคราะห์

**Q: ต้องส่งข้อมูลอะไร**

ส่งค่าหรือคอลัมน์ข้อมูล

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

- username-dax
- userprincipalname-dax
- userobjectid-dax
- userinfo-dax
- [CALCULATE – ฟังก์ชันหลักของ DAX ที่ควบคุม Filter Context](https://www.thepexcel.com/functions/dax/filter/calculate-dax/)
- [FILTER – กรองตารางด้วยเงื่อนไขที่ซับซ้อน (Iterator Function)](https://www.thepexcel.com/functions/dax/filter/filter-dax/)

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

- [Microsoft Learn: DAX](https://learn.microsoft.com/en-us/dax/function/customdata) _(documentation)_

---

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