Date: 2025-11-03 14:47
Status: Child
Tag: Power BI Power Query data modeling Data Analysis
π― Overview & Objectives
This session builds on the Power BI lifecycle introduced last week. We dive deep into Power Query β the ETL (Extract, Transform, Load) engine of Power BI.
Goals:
- Understand data connection from multiple sources.
- Master Power Query Editor for cleaning and reshaping.
- Learn GUI-based transformations (no coding required).
- Prepare data for modeling and visualization.
Target Audience: Beginners to intermediate analysts using Power BI Desktop.
π Full Power BI Lifecycle (Expanded)
After connecting data from multiple datasets (e.g., CSV files for customers, products, and sales from 2019-2021), we often find the data isnβt ready-made. For instance:
- Sales by region might require mapping continents.
- Fact tables may lack profit calculations or transaction details.
- We create dimension tables for breakdowns like region, country, quarter, specific days (e.g., evenings or afternoons), or time periods.
Transformations happen in Power Query, followed by data modeling and DAX calculations.
| Stage | Tools Used | Key Activities | Example |
|---|---|---|---|
| 1. Data Connection | Get Data | Import from Excel, CSV, SQL, Web, etc. | Connect 3 CSV + 2 SQL tables (e.g., Customers.csv, Sales_2019-2021.csv) |
| 2. Data Transformation | Power Query Editor | Clean, merge, split, calculate | Fix case, remove duplicates; create dimension tables (e.g., quarter, region-continent) |
| Power Query, Excel etc. | Create dimension tables | Region, country, specific date/time (e.g., evening/afternoon) | |
| 3. Data Modeling | Model View | Relationships, helper tables, dimensions | Link Sales β Customers |
| 4. DAX Calculations | DAX Formula Bar | Measures & calculated columns | Total Sales = SUM(Sales[Amount]) |
| 5. Visualization | Report View | Charts, tables, dashboards | Sales by Continent map |
| 6. Publishing | Power BI Service | Share online, schedule refresh | Embed in website |
Real-World Example:
Sales report using:
Sales_2021.csv(transactions)Customers.csv(demographics)Calendar.csv(dates)Products.csv(product details) β Combined into one interactive dashboard
β We will do this by using different dimension tables (e.g., region-continent mapping).
π οΈ Setting Up Power BI Desktop
π₯ Download & Install
- Go to powerbi.microsoft.com
- Download Power BI Desktop (Free)
- Run installer β Next β Next β Finish
System Requirements:
- Windows 10+
- 8 GB RAM recommended
- 64-bit OS
π Launch & Create Blank Report
- Open Power BI Desktop
- Click βBlank Reportβ
- Interface loads:
- Report View (default)
- Switch via left sidebar: Report β Data β Model
π Data Connection Deep Dive
Supported Data Import Sources (Partial List)
| Category | Examples |
|---|---|
| File | Excel (.xlsx), CSV/Text, JSON, XML |
| Database | SQL Server, Oracle, MySQL, PostgreSQL |
| Online | Web, SharePoint, Google Analytics |
| Power Platform | Dataverse, Dataflows |
| Other | Folder (combine multiple files), PDF |
Why CSV?
- Lightweight (1 MB vs 10 MB Excel) β Excel files include formatting, colors, filters, making them bloated and slower.
- No formatting bloat.
- Default export from ERPs (SAP, Oracle).
- When saving from Excel: Choose βCSV (Comma delimited)β for 1/10th the size; avoids full Excel configuration.
- Import Tip: File > Get Data > Text/CSV (or other types like Database, Fabric, Power Platform). Connect directly in Power BI or within Power Query for auto-loading.
Step-by-Step: Connect CSV
graph TD A[Home β Get Data] --> B[Text/CSV] B --> C[Select File: Customers.csv] C --> D[Preview Window] D --> E{Load or Transform?} E -->|Load| F[Direct to Model] E -->|Transform Data| G[Power Query Editor]
Preview Window Options
| Button | Behavior |
|---|---|
| Load | Imports raw data (skips cleaning); goes to DAX/Data Modeling in Power BI |
| Transform Data | Opens Power Query Editor β |
| Cancel | Abort connection |
Multiple Files Example: Start with
Customers.csv, then addSales_2019-2021.csvandProducts.csvvia New Source in Power Query.
π§Ή Power Query Editor: Full Interface Breakdown

βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Queries Pane | Data Preview Grid | Properties β
β - Customers | [Table View] | Query Name β
β - Sales | | Applied Steps β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Formula Bar (M Code)| Element | Function | Tips |
|---|---|---|
| Queries Pane | List of tables | Right-click β Rename, Duplicate, Reference; also rename via Properties or left bar |
| Data Preview | Live table view | Scroll, filter, sort |
| Formula Bar | Shows auto-generated M code | Toggle via View β Formula Bar |
| Applied Steps | Transformation log | Click step to preview; Delete to undo |
| Ribbon | Home, Transform, Add Column, View, Tools | Context-sensitive; key tabs: Home (basic), Transform (text/date), Add Column (custom) |
π οΈ Applied Steps Example
= Source β Connect to CSV
= Promoted Headers β First row β columns (auto)
= Changed Type β Detect data types (auto)
= Split Column by Delimiter β Email β User + Domain
= Capitalized Each Word β Mr. john β Mr. JohnUndo in Power Query: Delete step (not Ctrl+Z)
βοΈ Core Transformations (Home Tab)
β New Source
- Add another file mid-session
- Example: Start with
Customers.csvβ AddSales.csv
π Enter Data (Virtual Table)
Use Case: Map abbreviations, e.g., gender codes for analysis like βWhich gender buys what product?β (Male/Female vs. M/F).
| Code | Gender |
|---|---|
| M | Male |
| F | Female |
β Name: GenderMapping β Load to model.
π§ Data Source Settings
- Edit path:
D:\Data\Customers.csvβE:\Backup\ - Critical for shared projects
β‘ Refresh Preview
- Simulates live data
- Only during development
π οΈ Query Properties
| Option | Use |
|---|---|
| Enable Load | Include in final model |
| Include in Report Refresh | Auto-update on open |
πΉοΈ Manage Table
- Duplicate table
- Reference: Creates a child table; changes in child reflect in parent β use with caution to avoid unintended updates.
Transform vs. Add Column:
- Transform (e.g., in Transform tab): Modifies existing column in-place (saves memory).
- Add Column: Creates a new column (safer for testing; common for Format, Date/Time, Duration in Transform/Add Column tabs).
ποΈ Column & Row Operations
βοΈ Split Column by Delimiter (Advanced)
Email: john.doe@company.com
Delimiter: @
β Column1: john.doe
β Column2: company.comAdvanced Options:
- At each occurrence (like Excel)
- Leftmost / Rightmost
- Multi-character:
" - "or" FOR "
π Extract Text Functions
| Function | Syntax Example | Excel Equivalent | Power Query Note |
|---|---|---|---|
| Length | Text.Length([Occupation]) | =LEN() | Counts characters |
| First Chars | Text.Start([Code], 3) | =LEFT() | From start |
| Last Chars | Text.End([Code], 4) | =RIGHT() | From end |
| Range | Text.Middle([Code], 3, 4) | =MID(text, start+1, len) | 1-based index; start position not included in result (unlike Excel MID) |
Note: Power Query is 1-based index, but
Text.Middleadjusts logically (subtle difference from Excel: start point excluded).
Practical Example: Product Code
Input text like transaction descriptions requires extraction for clean analysis.
| Original Text | Goal | Power Query Step | Result |
|---|---|---|---|
| ACLG2402516 FOR SITE A-1253 DTD 24.08.2025 | Extract Code | Add Column β Text Before Delimiter β β FORβ | ACLG2402516 |
| ACLG2402516 FOR SITE A-1253 DTD 24.08.2025 | Extract Site ID | Add Column β Text Between Delimiters β βSITE β & β DTDβ | A-1253 |
| LG COMMISSIONS NO ACLG2402516 FOR SITE A-1253 DTD 24.08.2025 | Extract Code (Longer) | Add Column β Text After Delimiter β βNO β then Before β FORβ | ACLG2402516 |
Excel Alternatives (for comparison; use FIND for dynamic positions):
| Original Text | Excel Formula (Code) | Excel Formula (Site ID) | Result (Code) | Result (Site ID) |
|---|---|---|---|---|
| ACLG2402516 FOR SITE A-1253 DTD 24.08.2025 | =LEFT(A2,11) or =MID(A2,1,11) | =MID(A2,FIND("SITE ",A2)+5,6) | ACLG2402516 | A-1253 |
| LG COMMISSIONS NO ACLG2402516 FOR SITE A-1253 DTD 24.08.2025 | =MID(A2,FIND("NO ",A2)+3,11) | =MID(A2,FIND("SITE ",A2)+5,6) | ACLG2402516 | A-1253 |
Apply on [Occupation] column, e.g., βprofessionalβ:
- First Chars (3): βproβ
- Last Chars (4): βonalβ
- Range (start 4, length 4): βessiβ (start excluded).
π‘ Text Cleaning (Transform Tab)
| Operation | Before | After | Use Case |
|---|---|---|---|
| Capitalize Each Word | mr. john doe | Mr. John Doe | Names |
| Uppercase | sales rep | SALES REP | Codes |
| Lowercase | ProFessioNal | professional | Consistency |
| Trim | β hello " | "helloβ | Remove spaces |
| Clean | βHelloWorld" | "HelloWorldβ | Non-printable chars |
Transform = Modify in-place (saves memory)
Add Column = New column (safer for testing)
π Date & Time Mastery
Extract from BirthDate
| Component | Result | DAX/PQ Function |
|---|---|---|
| Year | 1965 | Date.Year([BirthDate]) |
| Month | 4 | Date.Month([BirthDate]) |
| Month Name | April | Format([BirthDate], "MMMM") |
| Quarter | Q2 | Date.Quarter([BirthDate]) |
| Day | 8 | Date.Day([BirthDate]) |
| Day of Week | Monday | Date.DayOfWeekName([BirthDate]) |
π°οΈ Age Calculation (Dynamic)
AgeInDays = Duration.Days(DateTime.LocalNow(), [BirthDate])
AgeInYears = AgeInDays / 365.25β Add Column β Date β Age (uses BirthDate vs. system date, e.g., Nov 3, 2025)
β Convert β Duration β Total Years
β Round: From Number β Rounding β Round (e.g., to whole years)
| BirthDate | System Date (Ex: Nov 3, 2025) | AgeInDays | AgeInYears (Rounded) |
|---|---|---|---|
| 1980-05-15 | 2025-11-03 | 16,520 | 45 |
| 1995-12-01 | 2025-11-03 | 10,945 | 30 |
Real-Time: Uses Control Panel date.
Use Case: Customer master analysis, e.g., age groups (Young/Middle/Senior) for segmentation.
π’ Number Transformations
| Category | Options |
|---|---|
| Rounding | Round, Up, Down |
| Scientific | 1.23E+10 |
| Statistics | Sum, Avg, Min, Max (on selection) |
| Trigonometry | Sin, Cos, etc. |
Custom Calculation Example
Bonus = [Salary] * 0.1β Add Column β Custom Column β Formula
π§© Advanced: Index & Conditional Columns (Preview)
π’ Index Column
- From 0 or From 1
- Reorder: Right-click β Move β To Beginning
β Conditional Column (Next Class)
Age Group =
if [Age] < 30 then "Young"
else if [Age] < 50 then "Middle"
else "Senior"β οΈ Performance & Best Practices
| Do | Donβt |
|---|---|
| Use Transform over Add Column | Create 10+ duplicate columns |
| Delete unnecessary steps | Keep raw import columns |
| Rename everything | Rely on Column1, Column2 |
| Test with 100 rows first | Transform full 1M rows |
Golden Rule:
Fewer steps = Faster refresh = Happier users
π Next Session: Power Query Level 2
| Topic | Details |
|---|---|
| Merge Queries | VLOOKUP on steroids |
| Append Queries | Stack tables (union) |
| Folder Connection | Auto-combine 100+ files |
| Conditional Logic | If-then-else columns |
| Error Handling | Replace, remove, fill |
β Q&A Expanded
Q: Power Query vs Excel Data Cleaning?
| Feature | Excel | Power Query |
|---|---|---|
| Split by multi-char | β | β |
| Auto M-code | β | β |
| Reusable steps | β | β |
| Handle 1M+ rows | Slow | Fast |
Q: Merge like VLOOKUP?
β Yes! Merge Queries = Left Join
β Covered in Data Modeling
π― Final Summary
| Concept | Key Command | Purpose |
|---|---|---|
| Connect | Get Data | Import raw |
| Clean | Trim, Clean | Fix text |
| Split | By Delimiter | Break columns |
| Extract | Text.Range | Substrings |
| Calculate | Custom Column | Math logic |
| Age | Duration.Days | Dynamic dates |
Practice Files:
Customers.csv,Sales_*.csv,Calendar.csv
β Apply: Split email, capitalize names, calculate age
Detailed notes from live training. Practice in Power BI Desktop for mastery.
Date: November 3, 2025