---
title: Function.From – แปลงฟังก์ชัน Unary เป็นฟังก์ชันหลายพารามิเตอร์
url: https://www.thepexcel.com/functions/power-query/function-values/function-from/
type: function-explainer
program: Power Query
syntax: "= Function.From(functionType as type, function as function) as function"
date: 2025-12-12
updated: 2025-12-23
scores:
  popularity: 3
  difficulty: 8
  usefulness: 5
---

# Function.From – แปลงฟังก์ชัน Unary เป็นฟังก์ชันหลายพารามิเตอร์

> Function.From ใช้เพื่อแปลงฟังก์ชันที่รับเฉพาะลิสต์เดียว (unary function) ให้กลายเป็นฟังก์ชันที่รับพา

## คำอธิบาย

Function.From ใช้เพื่อแปลงฟังก์ชันที่รับเฉพาะลิสต์เดียว (unary function) ให้กลายเป็นฟังก์ชันที่รับพารามิเตอร์แยกกัน

## Syntax

```excel
= Function.From(functionType as type, function as function) as function
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| functionType | Yes | type |  | ประเภท (type) ของฟังก์ชันใหม่ที่ต้องการสร้าง กำหนดจำนวนพารามิเตอร์และประเภทของแต่ละตัว |
| function | Yes | function |  | ฟังก์ชัน Unary (รับพารามิเตอร์เป็นลิสต์เดียว) ที่ต้องการแปลง |

## ตัวอย่าง

### 1. แปลง List.Sum เป็นฟังก์ชันสองพารามิเตอร์

```excel
let
    ConvertedSum = Function.From(
        type function (a as number, b as number) as number,
        List.Sum
    ),
    Result = ConvertedSum(5, 3)
in
    Result
```

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

Function.From แปลง List.Sum ให้รับพารามิเตอร์สองตัว (5, 3) แล้วสร้างลิสต์ {5, 3} ส่งให้ List.Sum ซึ่งรวมได้ 8

### 2. แปลงฟังก์ชัน Custom Unary เป็นฟังก์ชันสามพารามิเตอร์

```excel
let
    ConcatenateList = (list as list) as text =>
        Text.Combine(
            List.Transform(list, Text.From),
            "-"
        ),
    ConvertedConcat = Function.From(
        type function (a as text, b as text, c as text) as text,
        ConcatenateList
    ),
    Result = ConvertedConcat("Hello", "World", "Power")
in
    Result
```

**ผลลัพธ์:** `"Hello-World-Power"`

สร้างฟังก์ชัน ConcatenateList ที่รับลิสต์และรวมเป็นข้อความ จากนั้น Function.From แปลงให้รับพารามิเตอร์สามตัวแยกกัน

### 3. แปลง List.Max เป็นฟังก์ชันหาค่าสูงสุดจากพารามิเตอร์แยก

```excel
let
    FindMax = Function.From(
        type function (x as number, y as number, z as number) as number,
        List.Max
    ),
    Score1 = 78,
    Score2 = 92,
    Score3 = 85,
    HighestScore = FindMax(Score1, Score2, Score3)
in
    HighestScore
```

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

Function.From เปลี่ยน List.Max เป็นฟังก์ชันที่รับสามพารามิเตอร์ (78, 92, 85) จากนั้นหาค่าสูงสุดได้ 92

### 4. สร้าง wrapper function สำหรับการคำนวณ Average

```excel
let
    CalculateAverage = Function.From(
        type function (score1 as number, score2 as number, score3 as number) as number,
        (list) => List.Sum(list) / List.Count(list)
    ),
    Result = CalculateAverage(85, 90, 88)
in
    Result
```

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

สร้าง anonymous function ที่รับลิสต์และคำนวณค่าเฉลี่ย Function.From ช่วยให้เรียกได้เหมือน CalculateAverage(85, 90, 88) แทนการส่งลิสต์โดยตรง

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

- ใช้ type function เพื่อกำหนด interface ที่ชัดเจนของฟังก์ชันใหม่

- ตรวจสอบว่า unary function ที่คุณส่งมาสามารถจัดการกับลิสต์ที่มีจำนวนองค์ประกอบตรงกับจำนวนพารามิเตอร์ที่ระบุใน functionType

- Function.From มีประโยชน์มากเมื่อคุณต้องการสร้าง library function หรือ wrapper function ที่ใช้ซ้ำได้

- ควรใช้ anonymous function หรือ lambda expression เมื่อสร้าง wrapper เพื่อให้โค้ดกระชับขึ้น

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

**Q: Function.From ต่างจาก Function.Invoke ยังไง**

Function.From ใช้เพื่อแปลงฟังก์ชัน Unary ให้กลายเป็นฟังก์ชันหลายพารามิเตอร์ ส่วน Function.Invoke ใช้เพื่อเรียกใช้ฟังก์ชันที่มีพารามิเตอร์เป็นลิสต์

**Q: ต้องใช้ Function.From ตรงไหน**

สถานการณ์ที่ Function.Invoke มีประโยชน์คือเมื่อคุณต้องการสร้าง wrapper หรือปรับแต่งวิธีการรับพารามิเตอร์ของ unary function เพื่อให้ใช้งานได้สะดวกขึ้น

**Q: ทำไมไม่ใช้ฟังก์ชันปกติแทน**

บางครั้ง unary function ในตัวของ Power Query ไม่สามารถเปลี่ยนแปลงได้ Function.From ช่วยให้คุณสร้าง interface ใหม่ที่เหมาะกับความต้องการของคุณได้

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

- [Microsoft Learn - Function.From](https://learn.microsoft.com/en-us/powerquery-m/function-from) _(official)_
- [Power Query M Function Reference](https://learn.microsoft.com/en-us/powerquery-m/power-query-m-function-reference) _(official)_
- [Understanding Power Query M Functions](https://learn.microsoft.com/en-us/powerquery-m/understanding-power-query-m-functions) _(official)_
- [Power Query How - M Language Community](https://powerquery.how/) _(article)_

---

_Source: [https://www.thepexcel.com/functions/power-query/function-values/function-from/](https://www.thepexcel.com/functions/power-query/function-values/function-from/)_
