---
title: Table.View – สร้าง View ของตาราง
url: https://www.thepexcel.com/functions/power-query/table-functions/table-view/
type: function-explainer
program: Power Query
syntax: "Table.View(view as function, handlers as record) as table"
date: 2025-12-06
updated: 2025-12-17
scores:
  popularity: 3
  difficulty: 7
  usefulness: 4
---

# Table.View – สร้าง View ของตาราง

> สร้าง View Definition สำหรับ Custom Connector

## คำอธิบาย

สร้างหรือแก้ไขพฤติกรรมของตาราง สำหรับการพัฒนา Custom Connector และการจัดการ Query Folding

## Syntax

```excel
Table.View(view as function, handlers as record) as table
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| view | Yes | function |  | ฟังก์ชัน View (มักปล่อยเป็น null หากไม่ต้องการ override) |
| handlers | Yes | record |  | Record ที่ระบุ Handlers ต่างๆ (เช่น GetType, GetRows, OnTake) |

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

### Custom Connector Development

Custom Connector Development

### Implementing DirectQuery

Implementing DirectQuery

## ตัวอย่าง

### 1. Override Table Type (กำหนดประเภทข้อมูล)

```excel
let
    MyType = type table [ID = number, Name = text],
    View = Table.View(null, [
        GetType = () => MyType,
        GetRows = () => #table(MyType, {{1, "A"}, {2, "B"}})
    ])
in
    View
```

**ผลลัพธ์:** `Table (ID, Name) with Defined Type`

สร้างตารางเสมือนโดยกำหนด Type และข้อมูลผ่าน Handler `GetType` และ `GetRows` เพื่อให้ Power Query รู้จักโครงสร้าง

### 2. Implement Query Folding (OnTake)

```excel
let
    View = Table.View(null, [
        GetType = () => type table [ID = number],
        GetRows = () => ...,
        OnTake = (count) => ... // Logic to push Take (Top N) to data source
    ])
in
    View
```

**ผลลัพธ์:** `Table View with Folding Support`

ตัวอย่างโครงสร้าง (Concept) การใช้ `OnTake` เพื่อรองรับการส่งคำสั่ง `Top N` ไปยัง Data Source (Query Folding)

### 3. จัดการ Error Handling (OnInvoke)

```excel
let
    View = Table.View(null, [
        GetRows = () => ...,
        OnInvoke = (function, args) => ... // Custom logic
    ])
in
    View
```

**ผลลัพธ์:** `Table View`

ใช้ `OnInvoke` เพื่อดักจับและจัดการการเรียกใช้ฟังก์ชันต่างๆ กับตารางนี้ ป้องกันการเกิด Error ที่ไม่คาดคิด

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

- [Table.FromRows – สร้างตารางจากรายการแถว](https://www.thepexcel.com/functions/power-query/table-functions/table-fromrows/)
- [Table.FromRecords – สร้างตารางจากรายการ Record](https://www.thepexcel.com/functions/power-query/table-functions/table-fromrecords/)

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

- [Microsoft Docs](https://learn.microsoft.com/en-us/powerquery-m/table-view) _(official)_
- [PowerQuery.how](https://powerquery.how/table-view/) _(guide)_

---

_Source: [https://www.thepexcel.com/functions/power-query/table-functions/table-view/](https://www.thepexcel.com/functions/power-query/table-functions/table-view/)_
