Basic Power BI ตอนที่ 2: การ Clean ด้วย Power Query | Basic Power BI Part 2: Cleaning Data With Power Query (TH/EN)

Basic Power BI ตอนที่ 2: Clean ข้อมูลด้วย Power Query ก่อนเข้าโหมด Data Model

สรุปจากคลิปของช่อง Lin Davoy ซีรีส์ Basic Power BI ตอนที่ 2 ต่อจากตอนที่ 1 ที่พาไปรู้จักการนำเข้าข้อมูลและสร้างกราฟง่ายๆ มาถึงตอนที่ 2 นี้ Lin พาไปลงลึกกับขั้นตอนที่กินเวลามากที่สุดของคนทำ Data จริงๆ นั่นคือการ Clean ข้อมูลด้วย Power Query เพราะข้อมูลที่ได้มาจากหน้างานแทบไม่มีทางสะอาดพร้อมใช้ตั้งแต่แรก ต้องผ่านการจัดระเบียบก่อนเสมอถึงจะเอาไปทำกราฟหรือ Dashboard ได้อย่างมั่นใจ

ทำไมต้อง Clean ใน Power Query แทนที่จะแก้ใน Excel ตรงๆ

ในมุมคนทำงานจริง หลายคนเคยชินกับการเปิด Excel แล้วนั่งลบแถวหรือแก้ค่าด้วยมือทีละจุด ซึ่งใช้ได้ครั้งเดียวแต่พอมีข้อมูลใหม่เข้ามาก็ต้องมานั่งทำซ้ำอีก Lin อธิบายว่าจุดแข็งของ Power Query คือทุกขั้นตอนที่เราคลิกจะถูกบันทึกไว้เป็น Applied Steps โดยอัตโนมัติ พอมีข้อมูลเดือนใหม่เข้ามาก็แค่กด Refresh ระบบจะไล่ทำตามขั้นตอนเดิมให้ทั้งหมด ไม่ต้องมานั่งลบมือใหม่ทุกครั้ง

ขั้นตอน Clean พื้นฐานที่ใช้บ่อยที่สุด

Lin แนะนำว่าก่อนเอาไปสร้างกราฟ ควรผ่านการเช็คพื้นฐานเหล่านี้ก่อนเสมอ ไม่ว่าจะเป็นการยกหัวตารางให้ถูกแถว การกำหนดชนิดข้อมูลให้ตรงกับความเป็นจริง การลบแถวที่ซ้ำกัน และการตัดช่องว่างเกินออกจากข้อความ ซึ่งแต่ละขั้นตอนอาจดูเล็กน้อยแต่ถ้าข้ามไปมักจะไปโผล่เป็นปัญหาตอนคำนวณ Measure หรือทำกราฟทีหลัง

ขั้นตอน Cleanทำอะไรใช้เมื่อไหร่
Promote Headersยกแถวแรกขึ้นมาเป็นชื่อคอลัมน์ไฟล์ที่หัวตารางไม่ได้อยู่แถวบนสุดตั้งแต่ import
Change Data Typeกำหนดชนิดข้อมูล เช่น ตัวเลข วันที่ ข้อความป้องกัน Error ตอนคำนวณหรือ Sum
Remove Duplicatesลบแถวที่ข้อมูลซ้ำกันทั้งแถวตารางที่มีความเสี่ยง Import ซ้ำ
Trim / Cleanตัดช่องว่างส่วนเกินและอักขระที่มองไม่เห็นข้อความที่พิมพ์มาไม่เป็นมาตรฐาน
Unpivot Columnsแปลงคอลัมน์ให้กลายเป็นแถวตารางที่มีเดือนหรือปีอยู่เป็นคอลัมน์แยกกัน

Promote Headers และการตั้งชนิดข้อมูลให้ถูกต้อง

ปัญหาที่เจอบ่อยคือไฟล์ที่ Import เข้ามาแล้วแถวแรกกลายเป็น Column1 Column2 แทนที่จะเป็นชื่อคอลัมน์จริง ซึ่งแก้ได้ง่ายๆ ด้วยปุ่ม Use First Row as Headers ส่วนเรื่องชนิดข้อมูล Lin เตือนว่า Power Query มักเดาชนิดข้อมูลผิดโดยเฉพาะคอลัมน์วันที่หรือตัวเลขที่มีสัญลักษณ์ปนอยู่ จึงควรเช็คซ้ำทุกคอลัมน์ด้วยตัวเองก่อนเสมอ

Remove หรือ Unpivot คอลัมน์ที่อยู่ผิดรูป

อีกเทคนิคที่ Lin ใช้บ่อยคือ Unpivot Columns สำหรับตารางที่มีเดือนหรือปีถูกวางเป็นคอลัมน์แยกกัน เช่น Jan, Feb, Mar เพราะรูปแบบนี้เอาไปสร้างกราฟหรือ Relationship ได้ยาก การ Unpivot จะช่วยพลิกให้กลายเป็นแถวข้อมูลปกติที่พร้อมเอาไปวิเคราะห์ต่อได้ทันที รวมถึงการลบคอลัมน์ที่ไม่ได้ใช้ทิ้งไปตั้งแต่ต้น ก็ช่วยให้ไฟล์เบาและโหลดเร็วขึ้นด้วย

คุ้มไหมที่จะเสียเวลา Clean ข้อมูลก่อน

คำตอบจาก Lin คือคุ้มมาก เพราะเวลาที่เสียไปกับการ Clean ข้อมูลตั้งแต่ต้นเพียงครั้งเดียว จะช่วยประหยัดเวลาในระยะยาวทุกครั้งที่มีข้อมูลใหม่เข้ามา แค่กด Refresh ก็จบ ต่างจากการแก้ Excel มือที่ต้องเริ่มนับหนึ่งใหม่ทุกรอบ และที่สำคัญกว่านั้นคือกราฟที่ได้จะแม่นยำและน่าเชื่อถือกว่าข้อมูลที่ไม่ได้ผ่านการจัดระเบียบมาก่อน


Basic Power BI Part 2: Cleaning Data With Power Query Before The Data Model

This is summarized from the Lin Davoy channel, Basic Power BI Part 2. It follows Part 1, which covered importing data and building simple charts. Part 2 goes deep on the step that takes up the most time in real data work: cleaning data with Power Query. Data pulled straight from the source is almost never clean enough to use as is, it always needs organizing first before it can go into a chart or dashboard with confidence.

Why clean inside Power Query instead of fixing it directly in Excel

In practice, many people are used to opening Excel and manually deleting rows or fixing values one by one. That works once, but as soon as new data comes in, the whole manual process has to be repeated. Lin explains that the strength of Power Query is that every click is automatically recorded as an Applied Step. When a new month of data arrives, all it takes is hitting Refresh, and the same steps run automatically, no manual cleanup required each time.

The basic cleaning steps used most often

Lin recommends checking these basics before building any chart: making sure table headers land on the correct row, setting each column data type correctly, removing duplicate rows, and trimming extra spaces from text. Each step looks minor on its own, but skipping any of them tends to surface as a problem later when calculating measures or building charts.

Cleaning StepWhat It DoesWhen To Use It
Promote HeadersTurns the first row into column namesA file where headers did not land on the top row on import
Change Data TypeSets a column as number, date, or textPrevents errors when calculating or summing later
Remove DuplicatesDeletes rows that are exact duplicatesTables at risk of being imported more than once
Trim / CleanStrips extra spaces and invisible charactersText typed inconsistently at the source
Unpivot ColumnsTurns columns into rowsTables with months or years spread across separate columns

Promoting headers and setting the right data types

A common problem is a file that imports with the first row showing as Column1, Column2 instead of real column names, which is easily fixed with the Use First Row as Headers button. On data types, Lin warns that Power Query often guesses wrong, especially for date columns or numbers mixed with symbols, so every column is worth double-checking manually before moving on.

Removing or unpivoting columns that are in the wrong shape

Another technique Lin uses often is Unpivot Columns, for tables where months or years are spread across separate columns such as Jan, Feb, Mar. That layout is hard to chart or link with relationships. Unpivoting flips it into normal rows that are ready for analysis right away. Removing unused columns early also keeps the file lighter and faster to load.

Is it worth the time to clean data first

Lin answer is a clear yes. The time spent cleaning data once at the start pays off every time new data arrives afterward, a single Refresh takes care of it, unlike manual Excel fixes that start from zero every round. More importantly, the resulting charts end up more accurate and more trustworthy than data that skipped the cleanup step.


ติดตามข่าวสาร Data & AI ได้ที่:
Facebook: https://www.facebook.com/davoytech
YouTube: https://www.youtube.com/@linlinmhee

📌 อย่าลืมกด Like, Share และ Subscribe เป็นกำลังใจให้ด้วยนะคะ!

💬 เพื่อนๆ ใช้เวลานั่ง Clean ข้อมูลก่อนทำกราฟนานแค่ไหนคะ มาคอมเมนต์เล่าให้ฟังหน่อยว่าเจอปัญหาข้อมูลรกๆ แบบไหนบ่อยที่สุด

#Davoy #DavoyTech #Linlinmhee #เรียนAI #คอร์สAI #DataAndAI #PowerBI #BasicPowerBI #PowerQuery #DataCleaning

Chat Widget - Davoy.tech