วิธี Sort ใน Power BI เหมือนจะง่าย แต่ไม่ง่ายเลย | Sorting in Power BI Looks Easy, But It Really Is Not (TH/EN)

วิธี Sort ใน Power BI เหมือนจะง่าย แต่ไม่ง่ายเลย

สรุปจากคลิปของช่อง Lin Davoy ที่พูดถึงเรื่อง sort หรือการเรียงลำดับข้อมูลใน Power BI ซึ่งฟังดูเป็นเรื่องพื้นฐานที่สุด แค่กดปุ่ม A-Z หรือ Z-A ก็น่าจะจบ แต่ในมุมคนทำงานจริงกับ Dashboard ทุกวัน เรื่อง sort นี่แหละที่มักเป็นจุดที่ทำให้กราฟแสดงผลผิดเพี้ยน เดือนเรียงมั่ว หรือหมวดหมู่สินค้าไม่ได้อยู่ในลำดับที่อยากให้ลูกค้าเห็น

ทำไม Sort อัตโนมัติถึงไม่ตรงกับที่เราต้องการ

ปัญหาคลาสสิกที่สุดคือการเรียงชื่อเดือน Power BI จะมองชื่อเดือนเป็นข้อความธรรมดา แล้วเรียงตามตัวอักษร A-Z ผลคือ เมษายน มาก่อน มกราคม ทั้งที่ในความเป็นจริงมกราคมควรมาก่อน เช่นเดียวกับระดับความสำคัญ สูง-กลาง-ต่ำ หรือไซส์เสื้อ S-M-L-XL ที่ Power BI ไม่มีทางรู้เองว่าเราต้องการลำดับแบบไหน เพราะมันเห็นแค่ตัวหนังสือ ไม่เห็นความหมายเชิงลำดับที่อยู่เบื้องหลัง

Sort by Column คือกุญแจสำคัญที่มือใหม่มักมองข้าม

ทางแก้ที่ถูกต้องและยั่งยืนที่สุดคือฟีเจอร์ Sort by Column ในแท็บ Modeling ของ Power BI Desktop วิธีคิดคือสร้างคอลัมน์ผู้ช่วย (helper column) ที่เก็บลำดับเป็นตัวเลข เช่น มกราคม เท่ากับ 1 กุมภาพันธ์ เท่ากับ 2 ไปเรื่อย ๆ แล้วสั่งให้คอลัมน์ชื่อเดือนไป sort by คอลัมน์ตัวเลขนี้แทน ข้อดีคือทำครั้งเดียวที่ต้นทาง แล้วทุก Visual ในรายงานที่ดึงฟิลด์นี้ไปใช้จะเรียงลำดับถูกต้องอัตโนมัติ ไม่ต้องไปตั้งค่าซ้ำทีละกราฟ

กับดักที่มือใหม่มักเจอ Sort ในแต่ละ Visual ไม่เหมือนกัน

อีกจุดที่สร้างความสับสนคือการคลิกขวาแล้วสั่ง Sort ที่ตัว Visual โดยตรง วิธีนี้สะดวกและเห็นผลทันที แต่ผลลัพธ์จะติดอยู่แค่ Visual นั้นตัวเดียว ถ้าเอาฟิลด์เดียวกันไปทำกราฟอีกตัว ลำดับจะไม่ได้ติดตามไปด้วย ทำให้รายงานหน้าเดียวกันมีบางกราฟเรียงถูก บางกราฟเรียงผิด โดยที่คนทำเองก็งงว่าทำไมไม่เหมือนกัน จุดนี้คือความแตกต่างสำคัญระหว่าง sort ที่ตัว field หรือ model กับ sort ที่ตัว visual ที่ต้องแยกให้ออก

Sort กับ Hierarchy และการ Drill Down

เมื่อมีการทำ Hierarchy เช่น ปี ไตรมาส เดือน แล้วลอง Drill Down ลึกลงไป ลำดับที่เคยตั้งไว้ถูกต้องอาจดูเพี้ยนไปในบางระดับ เพราะ Power BI จัดการการเรียงในแต่ละระดับของ Hierarchy แยกจากกัน จึงควรตรวจสอบ Sort by Column ให้ครบทุกฟิลด์ที่อยู่ใน Hierarchy ไม่ใช่แค่ฟิลด์บนสุด

วิธี Sortเหมาะกับข้อดีข้อจำกัด
Sort by Column (Modeling)ต้องการลำดับที่กำหนดเอง เช่น ชื่อเดือน ระดับ ไซส์ตั้งครั้งเดียว ใช้ได้ทุก Visual ที่ดึงฟิลด์นั้นต้องสร้างคอลัมน์ตัวเลขช่วยเพิ่มในโมเดล
Visual-level Sort (คลิกขวาที่กราฟ)ต้องการเรียงเฉพาะกราฟนั้น เช่น มากไปน้อยตามยอดขายทำง่าย เห็นผลทันที ไม่ต้องแก้โมเดลใช้ได้แค่ Visual เดียว ไม่ติดไปกับฟิลด์อื่น
Sort by Measureต้องการเรียงตามค่าที่เปลี่ยนไปตามตัวกรองไดนามิกตามข้อมูลจริงเสมอลำดับเปลี่ยนเมื่อ Filter เปลี่ยน อาจดูไม่นิ่งสำหรับผู้ชม

สรุปแบบใช้งานจริง ถ้าเป็นฟิลด์ที่ต้องเรียงลำดับความหมายตายตัว เช่น ชื่อเดือน ระดับ ไซส์ ให้ตั้ง Sort by Column ที่โมเดลตั้งแต่ต้น จะได้ไม่ต้องแก้ทีละกราฟ ส่วน Visual-level sort เก็บไว้ใช้กับกรณีที่อยากดูมากสุดน้อยสุดตามค่าตัวเลขในแต่ละหน้าเท่านั้น


Sorting in Power BI Looks Easy, But It Really Is Not

This post is summarized from the Lin Davoy channel, covering a topic that sounds trivially simple: sorting data in Power BI. Just hit A-Z or Z-A, right? In practice, working with dashboards every day, sorting is one of the most common places where reports quietly break, with months out of order or categories not showing in the sequence customers expect.

Why Automatic Sort Rarely Matches What You Actually Want

The classic problem is month names. Power BI treats April and January as plain text and sorts them alphabetically, so April lands before January even though chronologically it should come after. The same happens with priority levels (High, Medium, Low) or shirt sizes (S, M, L, XL). Power BI has no idea what order you intend because it only sees text characters, not the ranking meaning behind them.

Sort by Column Is the Key Feature Beginners Miss

The proper, durable fix is the Sort by Column feature under the Modeling tab in Power BI Desktop. The idea: add a helper column holding a numeric order, January equals 1, February equals 2, and so on, then set the month-name column to sort by that numeric column instead. Do it once at the model level, and every visual in the report that uses that field will sort correctly automatically, with no need to repeat the setup chart by chart.

The Beginner Trap: Sort Behaves Differently Per Visual

Another common source of confusion is right-clicking a visual and sorting it directly. It is fast and shows results instantly, but the sort order stays local to that one visual. Drop the same field into another chart and the order will not follow, so a single report page can end up with some charts sorted correctly and others not, with no obvious reason why. This is the key distinction to keep in mind: sorting at the field or model level versus sorting at the individual-visual level.

Sort and Hierarchies When Drilling Down

Once you build a hierarchy, say Year, Quarter, Month, and drill down through it, a sort order that looked correct at the top level can appear off at a deeper level. That is because Power BI manages sort order per hierarchy level independently, so it is worth double-checking that Sort by Column is set on every field in the hierarchy, not just the top one.

Sort MethodBest ForProsLimitations
Sort by Column (Modeling)A fixed custom order: months, priority levels, sizesSet once, applies to every visual using that fieldRequires adding a numeric helper column to the model
Visual-level Sort (right-click chart)Sorting one specific chart, e.g. by sales high to lowQuick, instant, no model changes neededLocal to that one visual only, does not carry over
Sort by MeasureOrder that should react to whatever filter is appliedAlways dynamic, reflects live dataOrder shifts whenever the filter changes, which can look unstable to viewers

Practical verdict: for any field with a fixed meaningful order, such as months, levels, or sizes, set Sort by Column at the model level from the start, so you never have to fix it chart by chart. Reserve visual-level sort for genuine highest-to-lowest-by-value views on a single page.


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

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

💬 ใครเคยเจอปัญหากราฟใน Power BI เรียงลำดับผิดจนต้องนั่งไล่แก้ทีละตัวบ้าง มาแชร์กันค่ะว่าใช้วิธีไหนแก้ปัญหา

#Davoy #DavoyTech #Linlinmhee #เรียนAI #คอร์สAI #DataAndAI #PowerBI #Sort #PowerQuery #DataModel #DataAnalytics

Chat Widget - Davoy.tech