ThepExcel Logo
  • บทความ
    • Excel
      • Excel ทั่วไป
      • Excel Pivot Table
      • Excel Power Pivot
      • Power Query
      • Excel Array Formula
      • Excel VBA
      • Excel for Business
      • Excel and Maths
      • ฟังก์ชัน Excel ทั้งหมด
    • Power BI
      • Power Query
      • Data Model
      • DAX Formula
      • Power BI Report
    • Coding
      • Excel VBA
      • Python
      • Power Query M Code
    • AI
      • ChatGPT
      • Stable Diffusion
      • MidJourney
    • Highlights : บทความแนะนำ
    • คลิปวีดีโอ
  • อบรม
    • อบรมลูกค้าองค์กร
    • คอร์สออนไลน์ SkillLane
    • แนะนำวิทยากร
    • Excel/Power BI Skill Map
    • Quiz
  • Shop
    • คอร์สออนไลน์
    • สินค้าทั้งหมด
    • หนังสือเล่ม
    • E-Book
    • Cart
  • Download
    • Download ไฟล์จากเทพเอ็กเซล
    • ThepExcel-Mfx : M Code สำเร็จรูป
    • Date Table สำเร็จรูป
    • กราฟ My Skill
    • github.com/ThepExcel
  • รวม Link
    • รวม Link สอน Excel & Power BI ทั้งไทยและเทศ
    • รวม Link เกี่ยวกับ AI
    • รวม Link Coding
    • หนังสือแนะนำ
    • Facebook ThepExcel
    • YouTube ThepExcel
    • DAX Formatter
  • Contact
    • แนะนำ เทพเอ็กเซล (Thep Excel)
    • แนะนำวิทยากร : อาจารย์ ศิระ เอกบุตร (ระ)
    • นโยบายการคุ้มครองข้อมูลส่วนบุคคล (Privacy Policy)
  • Facebook
  • YouTube

IF vs CHOOSE vs VLOOKUP เปรียบเทียบฟังก์ชั่นทำหน้าที่ตัดสินใจ

if choose vlookup

Categories 📂

Excel ทั่วไป

Tags 🏷️

choose, IF, vlookup

“ชีวิตคนเราเต็มไปด้วยการตัดสินใจ…” จริงๆ แล้วคนเราตัดสินใจอยู่ตลอดเวลา (บางทีก็ตัดสินใจที่จะอยู่เฉยๆ 555) บางทีเราก็ต้องเลือกระหว่าง Choice 2 อย่าง แต่บางทีก็มี Choice มากมายนับไม่ถ้วน…

การทำงานกับ Excel ก็เช่นกัน หลายๆ ครั้งเราก็ต้องตัดสินใจ “ว่าถ้าข้อมูลเป็นแบบนี้ๆ แล้วจะให้เกิดเหตุการณ์อะไรขึ้น??”

ซึ่งจริงๆ แล้วการตัดสินใจใน Excel นั้นมีฟังก์ชั่นที่มาช่วยในเรื่องนี้หลายตัวด้วยกัน แต่ในบทความนี้ผมจะขอยกตัวอย่างฟังก์ชั่นที่น่าสนใจมากๆ 3 อัน นั่นคือ IF, CHOOSE, และ VLOOKUP นั่นเอง ซึ่งผมบอกเลยว่า นี่คือ “หัวใจสำคัญ” ที่จะทำให้คุณใช้ Excel ได้เก่งกาจขึ้นอีกมากครับ!!

ก่อนอื่น ขอเริ่มจากฟังก์ชั่นพื้นฐานที่สำคัญที่สุดในการคิดแบบตัดสินใจ นั่นคือ IF ครับ

สารบัญ

  • IF
  • CHOOSE
  • VLOOKUP
  • สรุปเปรียบเทียบฟังก์ชั่นแต่ละตัว

IF

IF แปลได้ตรงๆ ว่า “ถ้า” ซึ่งความหมายและหน้าที่ของฟังก์ชั่นก็ตรงตามคำศัพท์ครับ นั่นคือ “ถ้า เงื่อนไขเป็นจริง แล้วจะใช้สูตร xxx แต่ถ้าไม่จริงจะใช้สูตร yyy”

พูดง่ายๆ ว่า มีทางแยกในการตัดสินใจ แค่ 2 ทาง คือ ถ้าเงื่อนไขเป็นจริง ก็ไปทางหนึ่ง ถ้าเป็นเท็จก็ไปอีกทางหนึ่ง เหมือนว่าเราเดินมาเจอทางแยกที่มีป้ายบอกทางชี้ไปซ้ายกับขวา… และการที่เราจะไปต่อทางไหน ก็ขึ้นอยู่กับเงื่อนไขที่กำหนดไว้

ซึ่งเงื่อนไขที่ว่าก็คือสิ่งที่เขียนอยู่ในส่วนของ logical_test ในฟังก์ชั่น IF นั่นเอง ซึ่งจะต้องให้ผลลัพธ์ออกมาได้แค่ 2 อย่าง คือ TRUE กับ FALSE เท่านั้น!

if
โครงสร้างฟังก์ชั่น

=IF(logical_test,value_if_true,value_if_false) 
=IF(เงื่อนไขที่ต้องเช็คว่าจริงหรือเท็จ,ถ้าจริงใช้สูตรนี้,ถ้าเท็จใช้สูตรนี้)

เช่น ถ้า A1 คือ จำนวนงานที่มีตำหนิ ถ้างานมีตำหนิมากกว่า 10 ชิ้น โดนค่าปรับชิ้นละ 5000 บาท แต่ถ้าไม่เกิน 10 ชิ้นจะโดนปรับชิ้นละ 1000 บาท

ถ้าเราต้องการคำนวณค่าปรับใน A2 จะเขียนสูตรได้ว่า =IF(A1>10,5000*A1,1000*A1)
ซึ่งแปลได้ว่า ถ้า A1 > 10 ชิ้น (เงื่อนไข) ค่าปรับคือ 5000*A1 (กรณีจริง) แต่ถ้าไม่เกิน ค่าปรับคือ 1000*A1 (กรณีเท็จ) นั่นเอง

หมายเหตุ : เงื่อนไขอาจมีได้หลายเงื่อนไข ซึ่งเอามาผสมรวมกันได้ด้วยฟังก์ชั่นทางตรรกะ เช่น AND, OR, NOT จนสุดท้ายเหลือออกมาแค่ TRUE/FALSE

หมายเหตุ 2 : เนื่องจาก IF แยกได้แค่ 2 กิ่ง ถ้าอยากให้ผลลัพธ์มีได้มากกว่า 2 กิ่งให้ใช้ IF ซ้อนกันหลายๆ ชั้น

CHOOSE

หาก IF เปรียบเสมือนป้ายทางแยก 2 ทางแล้ว CHOOSE ก็เปรียบเสมือนลิฟท์ ที่มีปุ่มให้เลือกกดว่าจะไปชั้นไหน แล้วแต่ละชั้นจะใช้สูตรอะไร?

choose

ที่ผมเปรียบเทียบ CHOOSE เป็นเหมือนลิฟต์ เพราะว่า CHOOSE นั้นเรา จะต้องระบุตัวเลข ให้มันก่อน ว่า จะให้มันทำงานด้วยสูตรลำดับที่เท่าไหร่? (มีได้สูงสุด 254 สูตร!!)

โครงสร้างฟังก์ชั่น

=CHOOSE(index_num,value1,value2,value3,…,value254)
=CHOOSE(เลขลำดับสูตรที่จะให้ใช้,สูตรที่1,สูตรที่2,สูตรที่3,…,สูตรที่254)

เช่น =CHOOSE(3,A1+2,A1*2,A1/2,A1^2) จะได้ผลลัพธ์ว่า A1/2
เพราะว่าเราเลือกสูตร ลำดับที่3 จากสูตรทั้งหมดที่มีให้เลือกดังนี

  1. A1+2
  2. A1*2
  3. A1/2
  4. A1^2

หมายเหตุ : ในชีวิตจริง การที่จะกำหนดลำดับสูตรที่จะใช้ให้เป็นตัวเลขได้นั้นไม่ใช่เรื่องง่าย ซึ่งถ้าให้ผมแนะนำ ก็ต้องใช้ฟังก์ชั่นถัดไปนั่นคือ VLOOKUP มาช่วยตรงส่วน index_num นี้นั่นเอง

VLOOKUP

ตัวสุดท้ายที่จะพูดถึงคือฟังก์ชั่นสุดเจ๋งอย่าง VLOOKUP ซึ่งจริงๆ แล้วมีการทำงานถึง 2 โหมดด้วยกัน นั่นคือ VLOOKUP แบบ Approximate Match และ แบบ Exact Match

ซึ่งตัวที่ผมจะขอพูดถึงในที่นี้คือ VLOOKUP แบบ Exact Match ซึ่งเป็นแบบที่เราใช้งานกันบ่อยในชีวิตประจำวันแล้วกันครับ

ถ้าจะให้เปรียบเทียบ VLOOKUP แบบ Exact Match ผมคิดว่าเราสามารถเปรียบเทียบกับเวลาที่เรากำลังมองไปที่เมนูของร้านกาแฟได้เลยครับ (ตัวอย่างร้านกาแฟนี้ ผมได้แนวคิดมาจากเว็บ http://www.excelcampus.com/functions/excel-vlookup-explained/ ครับ อธิบายได้เห็นภาพมาก)

vlookup3

สิ่งที่เราทำคือ เราคิดว่าจะกินกาแฟชนิดไหน จากนั้นก็มองไล่หาชนิดกาแฟที่ต้องการ พอเจอแล้ว ก็ค่อยกวาดสายตาไปทางขวา เพื่อดูอีกทีว่า option แต่ละแบบ ราคาเป็นเท่าไหร่ ซึ่งเรียงกันอยู่ในรูปแบบหลายๆ คอลัมน์ (แถวเดียวกัน คือ กาแฟชนิดเดียวกัน)

โครงสร้างฟังก์ชั่น

=VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
=VLOOKUP(ข้อมูลที่สนใจ,ตารางอ้างอิง,ลำดับคอลัมน์ของผลลัพธ์ที่ต้องการ, อันสุดท้าย ใส่ 0 เพื่อบอกว่าใช้โหมด Exact Match)

ถ้าเป็นตัวอย่างกาแฟ สมมติว่าผมต้องการกิน Cappuccino (lookup_value) ผมก็จะมองไปที่เมนู (table_array) แล้วกวาดสายตาจากบนลงล่างจนเจอกับ Cappuccino…

จากนั้นก็จะกวาดสายไปมองไปทางขวา สมมติผมต้องการแบบเย็น ผมก็ต้องมองไปที่คอลัมน์ลำดับที่ 3 (col_index_num) แล้วสุดท้ายก็จะได้ราคา นั่นคือ 65 บาท กลับมานั่นเอง

ซึ่งจะเขียนเป็นสูตรเต็มๆ ได้ว่า

=VLOOKUP(“Cappuccino”,เมนูกาแฟ,3,0) ซึ่งจะได้ผลลัพธ์คือ 65 กลับมาครับ

หมายเหตุ : ผลลัพธ์ของ VLOOKUP สามารถเป็นค่าผลลัพธ์ได้อย่างเดียว ไม่สามารถใส่เป็นสูตรคำนวณเช่นเดียวกับ IF หรือ CHOOSE ได้

สรุปเปรียบเทียบฟังก์ชั่นแต่ละตัว

if-vlookup-compare - Excel2

สรูปแล้วฟังก์ชั่นแต่ละตัวก็มีข้อดีข้อเสียต่างกัน ซึ่งถ้าให้ผมแนะนำว่าควรใช้ตัวไหน ก็ให้ดูว่า ทางแยกตัดสินใจมีมากหรือน้อย ถ้ามีน้อยๆ แค่ 2 ทาง การใช้ IF ก็ค่อนข้างสะดวก

แต่ถ้ามีหลายทาง ก็ให้ดูว่าผลลัพธ์เป็นค่าธรรมดาหรือเป็นสูตรคำนวณ ถ้าเป็นสูตรคำนวณก็ต้องคิดเอาว่าจะถนัดใช้ IF ซ้อน IF หรือจะใช้ CHOOSE ดีกว่า

แต่ถ้ามีหลายทางแล้วผลลัพธ์เป็นค่าธรรมดาๆ ไม่ใช่สูตร ก็ใช้ VLOOKUP ได้เลยครับ!!

สำหรับคนที่อยากศึกษาต่อเพิ่มเติม ก็สามารถค้นหาคำว่า IF, CHOOSE, VLOOKUP ในเว็บผมได้เลยครับ มีให้อ่านอีกเยอะครับ ^^

แชร์ความรู้ให้เพื่อนๆ ของคุณ
15    
15    

ติดตามเทพเอ็กเซล

  • Facebook
  • YouTube

อบรมกับเทพเอ็กเซล

🔥 คอร์สใหม่ล่าสุด 🔥

การทำ Optimization ด้วย Excel Solver
สำหรับงานวางแผน
คอร์สออนไลน์ เทพเอ็กเซล
คอร์สออนไลน์ จากเทพเอ็กเซล ดูกี่รอบก็ได้
อบรม Excel / Power BI ให้องค์กรของคุณ

บทความล่าสุด

  • วิธีผสม Model สูตรผสมแบบโดนใจใน Stable Diffusion [Part7]
  • สอนทำรูปตัวเองคู่กับสาว ใน Stable Diffusion [Part6]
  • สอน Train Model ตัวเองใน Stable Diffusion [Part5]
  • 10 Levels การเขียนสูตร Excel ในยุคใหม่
  • บันได 10 ขั้น เริ่มเรียนรู้ M Code ขุมพลังของ Power Query
  • แนวทางฝึกฝน Excel ให้เก่งขึ้น
  • รวม Link เว็บ/เพจเกี่ยวกับ AI

บทความแนะนำ

🔥ฟังก์ชันทั้งหมดใน Excel 🔥

  • 10 Levels การเขียนสูตร Excel ในยุคใหม่
  • แกะเคล็ดวิชา Excel Wizard ในการแข่ง Speed Run Excel ระดับโลก
  • เจาะลึก CALCULATE ใน DAX แบบลึกสุดใจ : Part 1
  • Series สอนดึงข้อมูลจากเว็บ ด้วย Power Automate Desktop
  • สรุปการใช้ LAMBDA ฟังก์ชันที่ใช้สร้างฟังก์ชันใน Excel 365 และผองเพื่อน
  • วิธีใช้ Excel คำนวณระยะเวลาการทำงานรวม แถมระบุเวลาพักได้แบบยืดหยุ่น
  • วิธีจัดการข้อมูลแย่ๆ ด้วย Power Query ทั้งข้อมูลปนกัน ข้อมูลอยู่บนหัวตาราง

Categories

Tags

ai collection concepts copy database Data Model data validation date dax dropdown error excel filter finance find format formula function game graph IF index intro len link logic lookup match matrix mcode m code merge mid overview paste pivot power query row sort speed split stable diffusion substitute table text time tips trim vba vlookup

Archives

  • April 2023 (8)
  • March 2023 (2)
  • February 2023 (2)
  • January 2023 (1)
  • October 2022 (1)
  • September 2022 (3)
  • August 2022 (3)
  • July 2022 (1)
  • June 2022 (3)
  • May 2022 (1)
  • April 2022 (2)
  • February 2022 (1)
  • December 2021 (2)
  • November 2021 (10)
  • September 2021 (2)
  • August 2021 (6)
  • July 2021 (2)
  • June 2021 (2)
  • May 2021 (10)
  • April 2021 (3)
  • March 2021 (3)
  • February 2021 (4)
  • January 2021 (8)
  • December 2020 (5)
  • November 2020 (13)
  • October 2020 (5)
  • September 2020 (11)
  • August 2020 (4)
  • July 2020 (13)
  • June 2020 (17)
  • May 2020 (16)
  • April 2020 (16)
  • March 2020 (10)
  • February 2020 (15)
  • January 2020 (16)
  • December 2019 (4)
  • November 2019 (3)
  • October 2019 (9)
  • September 2019 (1)
  • August 2019 (7)
  • June 2019 (3)
  • May 2019 (9)
  • April 2019 (9)
  • March 2019 (2)
  • February 2018 (1)
  • January 2018 (3)
  • November 2017 (3)
  • August 2017 (1)
  • July 2017 (1)
  • June 2017 (1)
  • May 2017 (6)
  • April 2017 (6)
  • March 2017 (7)
  • February 2017 (1)
  • January 2017 (2)
  • December 2016 (1)
  • October 2016 (2)
  • September 2016 (3)
  • August 2016 (2)
  • July 2016 (2)
  • June 2016 (1)
  • May 2016 (1)
  • April 2016 (1)
  • March 2016 (2)
  • February 2016 (1)
  • January 2016 (2)
  • December 2015 (2)
  • November 2015 (5)
  • October 2015 (3)
  • June 2015 (2)
  • May 2015 (1)
  • April 2015 (26)
  • January 2015 (1)
  • December 2014 (1)
  • November 2014 (2)
  • October 2014 (1)
  • September 2014 (2)
  • August 2014 (1)
  • June 2014 (1)
  • May 2014 (1)
  • April 2014 (3)
  • March 2014 (3)
  • February 2014 (12)
  • January 2014 (7)
  • December 2013 (2)
  • November 2013 (8)
  • October 2013 (2)

เทพเอ็กเซล : Thep Excel

copyright © 2022

  • Facebook
  • YouTube
เว็บไซต์นี้ใช้คุกกี้ (Cookies)
บริษัท เทพเอ็กเซล จำกัด ให้ความสำคัญต่อข้อมูลส่วนบุคคลของท่าน เพื่อการพัฒนาและปรับปรุงเว็บไซต์รวมถึงสินค้าและบริการต่างๆ หากท่านใช้บริการเว็บไซต์นี้ โดยไม่มีการปรับตั้งค่าใดๆ แสดงว่าท่านยินยอมที่จะรับคุกกี้บนเว็บไซต์ และนโยบายสิทธิส่วนบุคคลของเรา
ตั้งค่าคุกกี้ยอมรับทั้งหมดอ่านเพิ่มเติม
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
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
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT