---
title: Table.ViewError – สร้าง View Error
url: https://www.thepexcel.com/functions/power-query/table-functions/table-viewerror/
type: function-explainer
program: Power Query
syntax: Table.ViewError(error as record) as any
date: 2025-12-06
updated: 2025-12-17
scores:
  popularity: 2
  difficulty: 7
  usefulness: 3
---

# Table.ViewError – สร้าง View Error

> สร้าง Error สำหรับ Table.View

## คำอธิบาย

สร้าง Error สำหรับ Table.View Handlers

## Syntax

```excel
Table.ViewError(error as record) as any
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| error | Yes | record |  | Record ที่ระบุรายละเอียดของ Error (เช่น Reason, Message) |

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

### Custom Connector Error Handling

Custom Connector Error Handling

## ตัวอย่าง

### 1. สร้าง Error แบบง่าย

```excel
Table.ViewError([Reason = "CustomError", Message = "Something went wrong"])
```

**ผลลัพธ์:** `Error Record`

สร้าง Error record เพื่อส่งกลับไปยัง Engine

### 2. ใช้ใน OnInvoke Handler

```excel
let
    View = Table.View(null, [
        GetRows = () => ...,
        OnInvoke = (function, args) => 
            if function = "RestrictedFunction" then
                Table.ViewError([Reason = "AccessDenied", Message = "Function not allowed"])
            else
                ...
    ])
in
    View
```

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

ตัวอย่างการใช้ Table.ViewError เพื่อปฏิเสธการเรียกใช้ฟังก์ชันบางอย่างใน Custom Connector

### 3. Error พร้อม Detail

```excel
Table.ViewError([
    Reason = "Expression.Error",
    Message = "Column not found",
    Detail = "Column ID does not exist"
])
```

**ผลลัพธ์:** `Error with Detail`

สร้าง Error ที่ระบุรายละเอียดเพิ่มเติมเพื่อช่วยในการ Debug

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

- [Table.View – สร้าง View ของตาราง](https://www.thepexcel.com/functions/power-query/table-functions/table-view/)
- [Error.Record – สร้างระเบียนข้อผิดพลาด](https://www.thepexcel.com/functions/power-query/error-handling/error-record/)

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

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

---

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