---
title: Date.QuarterOfYear – หาไตรมาสของปี
url: https://www.thepexcel.com/functions/power-query/date-functions/date-quarterofyear/
type: function-explainer
program: Power Query
syntax: Date.QuarterOfYear(dateTime as any) as nullable number
date: 2025-12-03
updated: 2025-12-26
scores:
  popularity: 6
  difficulty: 2
  usefulness: 6
---

# Date.QuarterOfYear – หาไตรมาสของปี

> คืนค่าไตรมาสของปี (1-4) จากวันที่ที่กำหนด ใช้สำหรับการวิเคราะห์ข้อมูลรายไตรมาส

## คำอธิบาย

คืนค่าไตรมาสของปี (1-4) จากวันที่ที่กำหนด ใช้สำหรับการวิเคราะห์ข้อมูลรายไตรมาส

## Syntax

```excel
Date.QuarterOfYear(dateTime as any) as nullable number
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| dateTime | Yes | date \| datetime \| datetimezone |  | วันที่ที่ต้องการหาไตรมาส ยอมรับ date, datetime หรือ datetimezone ได้ทั้งหมด |

## ตัวอย่าง

### 1. หาไตรมาสจากวันที่เดือน 4

```excel
Date.QuarterOfYear(#date(2025, 4, 1))
```

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

เดือนเมษายน (เมษายน-มิถุนายน) อยู่ในไตรมาส 2 ดังนั้นจึงคืนค่า 2

### 2. หาไตรมาสจากวันสิ้นปี

```excel
Date.QuarterOfYear(#date(2025, 12, 31))
```

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

วันที่ 31 ธันวาคมอยู่ในไตรมาส 4 (ตุลาคม-ธันวาคม) คืนค่า 4

### 3. เพิ่มคอลัมน์ไตรมาสในตาราง

```excel
let
    Source = Table.FromRecords({[SalesDate=#date(2025,2,10), Amount=1000], [SalesDate=#date(2025,8,15), Amount=1500]}),
    AddQuarter = Table.AddColumn(Source, "Quarter", each Date.QuarterOfYear([SalesDate]))
in
    AddQuarter
```

**ผลลัพธ์:** `ตาราง 3 คอลัมน์: SalesDate, Amount, Quarter (โดยจะแสดง 1 และ 3)`

ใช้ Table.AddColumn เพื่อเพิ่มคอลัมน์ใหม่ที่คำนวณไตรมาสจากคอลัมน์ SalesDate แต่ละแถว

### 4. ใช้กับ DateTime.LocalNow เพื่อหาไตรมาสปัจจุบัน

```excel
Date.QuarterOfYear(DateTime.LocalNow())
```

**ผลลัพธ์:** `4 (ขึ้นอยู่กับวันที่ปัจจุบัน)`

หาไตรมาสปัจจุบันจากสัญญาณนาฬิการะบบ ถ้าวันนี้คือ 26 ธันวาคม 2025 จะคืนค่า 4

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

- ผมแนะนำให้ใช้เป็นคอลัมน์ใหม่ในตารางสำหรับการรายงาน เพราะช่วยให้ group และ filter ง่ายขึ้น

- ส่วนตัวผม ชอบรวม Date.QuarterOfYear กับ Date.Year แล้ว concatenate เป็น Q1-2025 เพื่อให้อ่านง่ายกว่า

- ใช้ Table.AddColumn กับ each [DateColumn] เพื่อนำไปใช้กับทุกแถว มันเร็วและชัดเจน

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

**Q: ความแตกต่างระหว่าง Date.QuarterOfYear กับการใช้ Date.Month แล้วหาร 3 คืออะไร?**

ผมขอบอกว่า Date.QuarterOfYear สบายมาก คุณแค่เรียกฟังก์ชันนี้ไป ไม่ต้องไปคำนวณเองตามสูตร (Month-1)/3+1 อีก มันชัดเจน อ่านรู้เรื่อง และตรวจสอบได้ง่าย

**Q: ถ้า input เป็น null จะเกิดอะไรขึ้น?**

ฟังก์ชันจะคืนค่า null กลับมา ผมชอบสิ่งแบบนี้เพราะไม่มี error ที่น่ากังวล คุณแค่ใช้ Table.SelectRows เพื่อกรองแถว null ออกก่อนหากจำเป็น

**Q: ใช้ได้กับ datetimezone หรือไม่?**

ได้ครับ ผมลองแล้ว datetimezone, date, datetime ทั้งหมดใช้ได้ Power Query จะแปลงให้อัตโนมัติ

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

- [Date.Month – ดึงเดือนจากวันที่](https://www.thepexcel.com/functions/power-query/date-functions/date-month/)
- [Date.Year – ดึงปีจากวันที่](https://www.thepexcel.com/functions/power-query/date-functions/date-year/)

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

- [Microsoft Learn - Date.QuarterOfYear](https://learn.microsoft.com/en-us/powerquery-m/date-quarterofyear) _(official)_
- [PowerQuery.how - Date.QuarterOfYear](https://powerquery.how/date-quarterofyear/) _(article)_

---

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