---
title: Date.StartOfYear – หาวันต้นปี
url: https://www.thepexcel.com/functions/power-query/date-functions/date-startofyear/
type: function-explainer
program: Power Query
syntax: Date.StartOfYear(dateTime as any) as any
date: 2025-12-03
updated: 2025-12-26
scores:
  popularity: 6
  difficulty: 2
  usefulness: 6
---

# Date.StartOfYear – หาวันต้นปี

> Date.StartOfYear คืนค่าวันแรกของปี (1 มกราคม เวลา 00:00:00) จากวันที่ใดๆ ที่ส่งเข้ามา ใช้สำหรับคำนวณ

## คำอธิบาย

Date.StartOfYear คืนค่าวันแรกของปี (1 มกราคม เวลา 00:00:00) จากวันที่ใดๆ ที่ส่งเข้ามา ใช้สำหรับคำนวณตัวชี้วัดแบบ Year-To-Date หรือจัดกลุ่มข้อมูลตามปี

## Syntax

```excel
Date.StartOfYear(dateTime as any) as any
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| dateTime | Yes | date \| datetime \| datetimezone |  | วันที่หรือวันเวลาใดๆ ที่อยู่ในปีนั้น ฟังก์ชันจะคืนค่าวันแรกของปี |

## ตัวอย่าง

### 1. หาวันต้นปีจากวันที่

```excel
Date.StartOfYear(#date(2025, 5, 15))
```

**ผลลัพธ์:** `#date(2025, 1, 1)`

ส่งวันที่ 15 พฤษภาคม 2025 เข้าไป ฟังก์ชันจะคืนค่า 1 มกราคม 2025

### 2. ใช้กับ datetime

```excel
Date.StartOfYear(#datetime(2025, 10, 10, 8, 30, 45))
```

**ผลลัพธ์:** `#datetime(2025, 1, 1, 0, 0, 0)`

ส่งวันเวลา 10 ตุลาคม 2025 เวลา 08:30:45 เข้าไป จะได้ 1 มกราคม 2025 เวลา 00:00:00

### 3. ใช้ใน Power Query Table

```excel
= Table.AddColumn(#"Sales Data", "Year Start", each Date.StartOfYear([OrderDate]))
```

**ผลลัพธ์:** `เพิ่มคอลัมน์ใหม่ชื่อ Year Start ที่เก็บวันต้นปี`

ใช้กับ each เพื่อใช้กับแต่ละแถว ฟังก์ชันจะหาวันต้นปีของวันที่ในคอลัมน์ OrderDate

### 4. คำนวณ Year-To-Date Days

```excel
= Duration.Days(Date.StartOfYear(DateTime.Now()) - DateTime.Now())
```

**ผลลัพธ์:** `จำนวนวันตั้งแต่ต้นปีถึงวันนี้ (เป็นลบ)`

คำนวณระยะเวลาจากวันต้นปีถึงวันปัจจุบัน ใช้ Duration.Days เพื่อแปลงเป็นจำนวนวัน

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

- ผมใช้ Date.StartOfYear ร่วมกับ Duration.Days เพื่อหาจำนวนวันตั้งแต่ต้นปี

- ส่วนตัวผม ผมมักใช้ this ฟังก์ชันใน Table.AddColumn เพื่อเพิ่มคอลัมน์วันต้นปี

- ผมแนะนำให้ใช้ error handling เช่น try-catch เวลาทำงานกับข้อมูลที่อาจมี NULL

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

**Q: Date.StartOfYear แตกต่างจาก Date.StartOfMonth อย่างไร?**

ผมใช้ Date.StartOfYear เวลาต้องการวันต้นปี (1 มกราคม) และใช้ Date.StartOfMonth เวลาต้องการวันต้นเดือน ทั้ง 2 ฟังก์ชันทำงานคล้ายกัน แต่ช่วงเวลาที่ส่งกลับมาต่างกัน

**Q: ถ้าส่ง NULL หรือค่าว่างเข้าไป จะเกิดอะไรขึ้น?**

ฟังก์ชันจะส่งกลับมาเป็น error หรือ null ขึ้นอยู่กับการตั้งค่า ผมแนะนำให้ใช้ Table.TransformColumns หรือ each เพื่อตรวจสอบค่าก่อน

**Q: เวลาไหนที่ผมจะใช้ Date.StartOfYear?**

ผมใช้เวลาคำนวณ YTD metrics, จัดกลุ่มข้อมูลตามปี, หรือเปรียบเทียบข้อมูล Year-Over-Year ฟังก์ชันนี้ช่วยหาจุดเริ่มต้นของแต่ละปีได้เร็ว

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

- [Date.EndOfYear – หาวันสิ้นปี](https://www.thepexcel.com/functions/power-query/date-functions/date-endofyear/)
- [Date.Year – ดึงปีจากวันที่](https://www.thepexcel.com/functions/power-query/date-functions/date-year/)

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

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

---

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