Thep Excel

MAX – หาค่าสูงสุดในคอลัมน์หรือเปรียบเทียบสองค่า

MAX คืนค่าสูงสุดจากคอลัมน์ภายใต้ filter context หรือเปรียบเทียบสองค่าสเกลาร์แล้วเลือกค่าที่มากกว่า ทำงานกับ numeric, date และ text columns โดย scan ทุก row ที่ผ่าน filter แล้วเลือกค่าสูงสุด เหมาะสำหรับ measures และ calculated columns (ต้อง wrap ด้วย CALCULATE)

=MAX(<column>)

By ThepExcel AI Agent
18 December 2025

Function Metrics


Popularity
9/10

Difficulty
2/10

Usefulness
9/10

Syntax & Arguments

=MAX(<column>)

Argument Type Required Default Description
column column reference Yes คอลัมน์ที่ต้องการหาค่าสูงสุด ต้องใช้รูปแบบ Table[Column] เช่น Sales[Amount] หรือ Products[Price] ฟังก์ชันจะ scan ทุก row ที่ผ่าน filter context และคืนค่าสูงสุด รองรับ numeric, date และ text columns
expression1 scalar expression Yes ค่าสเกลาร์ตัวแรกที่ต้องการเปรียบเทียบ (ใช้ในรูปแบบสองอาร์กิวเมนต์) อาจเป็น measure, ค่าคงที่ หรือ expression ที่คืนค่าเดียว เช่น [Total Sales] หรือ 10000
expression2 scalar expression Yes ค่าสเกลาร์ตัวที่สองที่ต้องการเปรียบเทียบ (ใช้ในรูปแบบสองอาร์กิวเมนต์) BLANK ถูก treat เป็น 0 เมื่อเปรียบเทียบ เช่น MAX(-5, BLANK()) จะเปรียบเทียบ -5 กับ 0 และคืน 0 (ค่าดิบเป็น BLANK)

How it works

หาค่าสูงสุดในคอลัมน์ตัวเลข

หาราคาสูงสุด ยอดขายสูงสุด หรือปริมาณสูงสุดในข้อมูลที่ถูก filter อยู่ในขณะนั้น

หาวันที่ล่าสุด (Latest Date)

ใช้ MAX กับคอลัมน์ Date เพื่อหาวันที่ล่าสุดในช่วงที่เลือก เช่น หาวันที่ของ transaction ล่าสุด

เปรียบเทียบสอง measure หรือค่าคงที่

เลือกค่าที่มากกว่าระหว่าง actual กับ budget หรือระหว่างยอดจริงกับค่า threshold ที่กำหนด

ใช้ร่วมกับ CALCULATE เพื่อ modify filter context

หาค่าสูงสุดในเงื่อนไขพิเศษ เช่น ราคาสูงสุดของสินค้าที่ Active หรือยอดขายสูงสุดของปีที่แล้ว

Examples

ตัวอย่างที่ 1: หาค่าสูงสุดในคอลัมน์เดียว (Simple)
// Measure: หาราคาสินค้าสูงสุดในบริบทปัจจุบัน Highest Price = MAX(Products[UnitPrice]) // Context: Products table มี UnitPrice column // Filter context: ถูกกำหน…
MAX scan ทุก row ที่อยู่ใน filter context ปัจจุบัน (เช่น category ที่เลือกจาก slicer) แล้วคืนค่า UnitPrice สูงสุด นี่คือ aggregation function ที่ทำงานกับ filter context โดยตรง ไม่สร้าง row context ดังนั้นใช้ใน measure ได้ทันทีโดยไม่ต้อง wrap ด้วย CALCULATE ผลลัพธ์จะเปลี่ยนไปตาม filter ที่ใช้ในแต่ละ visual
DAX Formula:

// Measure: หาราคาสินค้าสูงสุดในบริบทปัจจุบัน
Highest Price = MAX(Products[UnitPrice])

// Context: Products table มี UnitPrice column
// Filter context: ถูกกำหนดโดย slicer/filter ใน visual
// Result: คืนค่าราคาสูงสุดจาก rows ที่ผ่าน filter

Result:

ถ้า filter เลือก Category = "Electronics" และมีราคา 500, 1200, 890 → คืน 1200

ตัวอย่างที่ 2: เปรียบเทียบสองค่า (Threshold Logic)
// Measure: เลือกค่าที่มากกว่าระหว่างยอดขายจริงกับ minimum threshold Sales Above Minimum = VAR ActualSales = SUM(Sales[Amount]) VAR MinimumThreshold = 10000 RET…
รูปแบบสองค่าของ MAX เปรียบเทียบ scalar expression สองค่า ในตัวอย่างนี้ใช้ VAR เพื่อคำนวณยอดขายจริงและเปรียบเทียบกับค่า threshold ถ้าค่าจริงต่ำกว่า threshold จะแสดงค่า minimum แทน pattern นี้มีประโยชน์ในการกำหนด floor value สำหรับ business logic เช่น minimum commission, minimum target หรือ guaranteed baseline
DAX Formula:

// Measure: เลือกค่าที่มากกว่าระหว่างยอดขายจริงกับ minimum threshold
Sales Above Minimum =
VAR ActualSales = SUM(Sales[Amount])
VAR MinimumThreshold = 10000
RETURN
    MAX(ActualSales, MinimumThreshold)

// Context: ใช้เพื่อแสดงผลไม่ต่ำกว่า threshold
// Result: ถ้า ActualSales = 8000 จะคืน 10000 (threshold)
// Result: ถ้า ActualSales = 15000 จะคืน 15000 (actual)

Result:

ActualSales = 15000 → คืน 15000 | ActualSales = 8000 → คืน 10000 (threshold)

ตัวอย่างที่ 3: หาวันที่ล่าสุด (Latest Date Pattern)
// Measure: หาวันที่ของ order ล่าสุดในบริบทปัจจุบัน Latest Order Date = MAX(Sales[OrderDate]) // Calculated Column: วันที่ล่าสุดของลูกค้าแต่ละคน (row context) C…
MAX ทำงานกับ Date column ได้เพราะ Date ใน DAX เก็บเป็น serial number (ตัวเลข) ดังนั้นค่าสูงสุด = วันที่ล่าสุด ในรูปแบบ measure ใช้ MAX โดยตรง แต่ใน calculated column ต้อง wrap ด้วย CALCULATE เพื่อทำ context transition (แปลง row context เป็น filter context) ไม่เช่นนั้น MAX จะไม่สามารถทำงานใน row context ได้
DAX Formula:

// Measure: หาวันที่ของ order ล่าสุดในบริบทปัจจุบัน
Latest Order Date = MAX(Sales[OrderDate])

// Calculated Column: วันที่ล่าสุดของลูกค้าแต่ละคน (row context)
Customer Latest Order =
CALCULATE(
    MAX(Sales[OrderDate])
)

// Context Behavior:
// - Measure: filter context จาก visual (เช่น filter by customer)
// - Calculated Column: CALCULATE สร้าง filter context จาก row context ของแต่ละ customer

Result:

Measure: ถ้า filter เลือก Customer A → คืน 2024-12-10 | Column: แต่ละ row คืนวันที่ล่าสุดของลูกค้านั้น

ตัวอย่างที่ 4: ใช้ร่วมกับ CALCULATE (Advanced Filtering)
// Measure: หาราคาสูงสุดของสินค้าที่ Active เท่านั้น Max Active Product Price = CALCULATE( MAX(Products[UnitPrice]), Products[Status] = "Active" ) // Measure: เ…
CALCULATE modify filter context โดยเพิ่มหรือแทนที่ filter condition (Products[Status] = "Active") ก่อนที่ MAX จะ scan หาค่าสูงสุด ในตัวอย่างที่สอง ใช้ VAR เก็บยอดขายสองปีแล้วเปรียบเทียบด้วย MAX รูปแบบสองค่า pattern นี้มีประโยชน์มากในการวิเคราะห์ year-over-year หรือ conditional maximum โดยใช้ SAMEPERIODLASTYEAR เพื่อเลื่อน filter context ไปปีที่แล้ว
DAX Formula:

// Measure: หาราคาสูงสุดของสินค้าที่ Active เท่านั้น
Max Active Product Price =
CALCULATE(
    MAX(Products[UnitPrice]),
    Products[Status] = "Active"
)

// Measure: เปรียบเทียบยอดขายปีนี้กับปีที่แล้ว แล้วเลือกค่าที่สูงกว่า
Higher Sales Year =
VAR CurrentYearSales = SUM(Sales[Amount])
VAR LastYearSales =
    CALCULATE(
        SUM(Sales[Amount]),
        SAMEPERIODLASTYEAR('Date'[Date])
    )
RETURN
    MAX(CurrentYearSales, LastYearSales)

// Context: CALCULATE modifies filter context ก่อนที่ MAX จะทำงาน

Result:

Max Active: ถ้ามี Active products ราคา 200, 500, 300 → คืน 500 | Higher Sales: 2024 Sales = 50000, 2023 Sales = 60000 → คืน 60000

FAQs

MAX กับ MAXX ต่างกันอย่างไร?

MAX ทำงานกับคอลัมน์ที่มีอยู่แล้วใน filter context โดยตรง ไม่สร้าง row context ส่วน MAXX เป็น iterator function ที่สร้าง row context และคำนวณ expression ในแต่ละ row ก่อนหาค่าสูงสุด ใช้ MAX เมื่อต้องการหาค่าสูงสุดจากคอลัมน์เดียว เช่น MAX(Sales[Amount]) แต่ใช้ MAXX เมื่อต้องการคำนวณ expression ในแต่ละ row เช่น MAXX(Sales, Sales[Quantity] * Sales[UnitPrice]) นอกจากนี้ MAX (สองค่า) treat BLANK as 0 แต่ MAXX ignore BLANK ทั้งหมด

MAX จัดการค่า BLANK อย่างไร?

ในรูปแบบคอลัมน์ MAX จะข้าม BLANK ไปและคืนค่าสูงสุดจากค่าที่ไม่ใช่ BLANK ถ้าทุกค่าเป็น BLANK จะคืน BLANK ในรูปแบบสองค่า BLANK ถูก treat เป็น 0 เช่น MAX(-5, BLANK()) จะเปรียบเทียบ -5 กับ 0 และคืน 0 (ค่าดิบคือ BLANK) เพราะ 0 > -5 ควรใช้ IF(ISBLANK(…), default_value, …) เพื่อจัดการกรณีพิเศษอย่างปลอดภัย

ใช้ MAX ใน measure กับ calculated column ต่างกันอย่างไร?

ใน measure MAX ทำงานกับ filter context จาก visual/slicer โดยตรง เช่น MAX(Sales[Amount]) จะหาค่าสูงสุดจาก rows ที่ผ่าน filter ใน calculated column ต้องใช้ CALCULATE เพื่อทำ context transition (แปลง row context เป็น filter context) เช่น CALCULATE(MAX(Sales[OrderDate])) ไม่เช่นนั้น MAX จะไม่ทำงานใน row context

MAX รองรับ data type อะไรบ้าง?

MAX รองรับ numeric types (Integer, Decimal, Currency) และ Date/DateTime (เพราะ Date เก็บเป็นตัวเลข serial number) ไม่รองรับ Boolean (TRUE/FALSE) โดยตรง ถ้าต้องการใช้กับ Boolean ให้ใช้ MAXA แทน สำหรับ Text columns MAX จะเปรียบเทียบตามลำดับตัวอักษร (alphabetically) และคืนค่าที่อยู่ท้ายสุด

ใช้ MAX กับ Date column ได้อย่างไร?

MAX ทำงานกับ Date ได้เพราะ Date ใน DAX เก็บเป็น serial number ดังนั้นค่าสูงสุด = วันที่ล่าสุด เช่น MAX(Sales[OrderDate]) จะคืนวันที่ล่าสุดใน filter context ปัจจุบัน pattern นี้มีประโยชน์มากในการหา last transaction date, latest update date หรือ end date ของช่วงเวลา ใช้ร่วมกับ CALCULATE และ SAMEPERIODLASTYEAR เพื่อเปรียบเทียบวันที่ระหว่างช่วงเวลาต่างกัน

เมื่อไหร่ควรใช้ MAX แทน SUM?

ใช้ MAX เมื่อต้องการหาค่าเดียวที่สูงสุดจากคอลัมน์ (single maximum value) ส่วน SUM ใช้เพื่อรวมค่าทั้งหมด ตัวอย่าง: MAX(Sales[Amount]) = 5000 (ค่า transaction เดียวที่สูงสุด) แต่ SUM(Sales[Amount]) = 50000 (ยอดรวมทั้งหมด) ไม่ควรสับสนระหว่าง aggregation ประเภทต่างกัน MAX ตอบคำถาม “ค่าสูงสุดคือเท่าไหร่” ส่วน SUM ตอบคำถาม “ยอดรวมทั้งหมดคือเท่าไหร่”

MAX performance เป็นอย่างไร เมื่อเทียบกับ MAXX?

MAX มี performance เทียบเท่า MAXX เมื่อใช้กับคอลัมน์เดียวเพราะใน DAX engine MAX() ภายในทำงานเหมือน MAXX(

, ) แต่เมื่อใช้ MAXX กับ complex expression (เช่น การคำนวณหลายคอลัมน์) จะช้ากว่าเพราะต้อง iterate และคำนวณในแต่ละ row สิ่งสำคัญคือเลือกใช้ตาม logic requirement ไม่ใช่ performance optimization เพราะ DAX engine มี query optimizer ที่ดีอยู่แล้ว

Resources & Related

Additional Notes

MAX เป็นฟังก์ชัน aggregation พื้นฐานใน DAX ที่ใช้หาค่าสูงสุดภายใต้ filter context ปัจจุบัน มี 2 รูปแบบการใช้งาน: (1) หาค่าสูงสุดในคอลัมน์ทั้งหมด และ (2) เปรียบเทียบสองค่าสเกลาร์แล้วคืนค่าที่มากกว่า ฟังก์ชันนี้ทำงานกับ numeric, date และ text columns โดย iterate ทุก row ที่ผ่าน filter context แล้วเลือกค่าสูงสุดออกมา เหมาะสำหรับการวิเคราะห์ค่าสูงสุด เช่น ราคาสินค้าสูงสุด ยอดขายสูงสุดในแต่ละภูมิภาค หรือหาวันที่ล่าสุดในช่วงเวลาที่กำหนด ใช้ได้ทั้งใน measure และ calculated column (ต้อง wrap ด้วย CALCULATE ใน calculated column)

MAX ทำงานใน filter context ซึ่งหมายความว่าผลลัพธ์จะเปลี่ยนไปตาม slicer, filter หรือ visual filter ที่ใช้อยู่ในขณะนั้น เมื่อใช้กับคอลัมน์ DAX จะ scan แต่ละ row ที่ผ่าน filter แล้วเลือกค่าสูงสุด สำหรับรูปแบบสองค่า MAX จะเปรียบเทียบ scalar expression สองค่าและคืนค่าที่มากกว่า โดย treat BLANK เป็น 0 เมื่อเปรียบเทียบ (แตกต่างจาก MAXX ที่ ignore BLANK โดยสมบูรณ์) ความแตกต่างสำคัญระหว่าง MAX กับ MAXX: MAX ทำงานกับคอลัมน์ที่มีอยู่แล้วใน filter context ไม่สร้าง row context ส่วน MAXX เป็น iterator function ที่สร้าง row context และคำนวณ expression ในแต่ละ row ก่อนหาค่าสูงสุด

ใช้ MAX เมื่อต้องการหาค่าสูงสุดจากคอลัมน์เดียว เช่น MAX(Sales[Amount]) หาค่า transaction เดียวที่สูงสุด แต่ใช้ MAXX เมื่อต้องการคำนวณ expression ในแต่ละ row ก่อนหาค่าสูงสุด เช่น MAXX(Sales, Sales[Quantity] * Sales[UnitPrice]) คำนวณ total price แต่ละ row แล้วหาค่าสูงสุด นอกจากนี้ MAX แบบสองค่ามีประโยชน์สำหรับ threshold logic เช่น MAX([Actual Sales], 10000) เพื่อให้ค่าไม่ต่ำกว่า 10,000 หรือเปรียบเทียบระหว่าง current vs previous period แล้วเลือกค่าที่สูงกว่า ใช้ร่วมกับ CALCULATE เพื่อ modify filter context ก่อน aggregation เช่น หาราคาสูงสุดของสินค้าที่ Active เท่านั้น

Leave a Reply

Your email address will not be published. Required fields are marked *

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Performance
Analytics
Advertisement
Others