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.

StageTools UsedKey ActivitiesExample
1. Data ConnectionGet DataImport from Excel, CSV, SQL, Web, etc.Connect 3 CSV + 2 SQL tables (e.g., Customers.csv, Sales_2019-2021.csv)
2. Data TransformationPower Query EditorClean, merge, split, calculateFix case, remove duplicates; create dimension tables (e.g., quarter, region-continent)
Power Query, Excel etc.Create dimension tablesRegion, country, specific date/time (e.g., evening/afternoon)
3. Data ModelingModel ViewRelationships, helper tables, dimensionsLink Sales β†’ Customers
4. DAX CalculationsDAX Formula BarMeasures & calculated columnsTotal Sales = SUM(Sales[Amount])
5. VisualizationReport ViewCharts, tables, dashboardsSales by Continent map
6. PublishingPower BI ServiceShare online, schedule refreshEmbed 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

  1. Go to powerbi.microsoft.com
  2. Download Power BI Desktop (Free)
  3. Run installer β†’ Next β†’ Next β†’ Finish

System Requirements:

  • Windows 10+
  • 8 GB RAM recommended
  • 64-bit OS

πŸš€ Launch & Create Blank Report

  1. Open Power BI Desktop
  2. Click β€œBlank Report”
  3. Interface loads:
    • Report View (default)
    • Switch via left sidebar: Report ↔ Data ↔ Model

πŸ“‚ Data Connection Deep Dive

Supported Data Import Sources (Partial List)

CategoryExamples
FileExcel (.xlsx), CSV/Text, JSON, XML
DatabaseSQL Server, Oracle, MySQL, PostgreSQL
OnlineWeb, SharePoint, Google Analytics
Power PlatformDataverse, Dataflows
OtherFolder (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

ButtonBehavior
LoadImports raw data (skips cleaning); goes to DAX/Data Modeling in Power BI
Transform DataOpens Power Query Editor βœ…
CancelAbort connection

Multiple Files Example: Start with Customers.csv, then add Sales_2019-2021.csv and Products.csv via 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)
ElementFunctionTips
Queries PaneList of tablesRight-click β†’ Rename, Duplicate, Reference; also rename via Properties or left bar
Data PreviewLive table viewScroll, filter, sort
Formula BarShows auto-generated M codeToggle via View β†’ Formula Bar
Applied StepsTransformation logClick step to preview; Delete to undo
RibbonHome, Transform, Add Column, View, ToolsContext-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. John

Undo in Power Query: Delete step (not Ctrl+Z)


βš™οΈ Core Transformations (Home Tab)

βž• New Source

  • Add another file mid-session
  • Example: Start with Customers.csv β†’ Add Sales.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).

CodeGender
MMale
FFemale

β†’ 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

OptionUse
Enable LoadInclude in final model
Include in Report RefreshAuto-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.com

Advanced Options:

  • At each occurrence (like Excel)
  • Leftmost / Rightmost
  • Multi-character: " - " or " FOR "

πŸ“ Extract Text Functions

FunctionSyntax ExampleExcel EquivalentPower Query Note
LengthText.Length([Occupation])=LEN()Counts characters
First CharsText.Start([Code], 3)=LEFT()From start
Last CharsText.End([Code], 4)=RIGHT()From end
RangeText.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.Middle adjusts logically (subtle difference from Excel: start point excluded).

Practical Example: Product Code

Input text like transaction descriptions requires extraction for clean analysis.

Original TextGoalPower Query StepResult
ACLG2402516 FOR SITE A-1253 DTD 24.08.2025Extract CodeAdd Column β†’ Text Before Delimiter β†’ ” FOR”ACLG2402516
ACLG2402516 FOR SITE A-1253 DTD 24.08.2025Extract Site IDAdd Column β†’ Text Between Delimiters β†’ β€œSITE ” & ” DTD”A-1253
LG COMMISSIONS NO ACLG2402516 FOR SITE A-1253 DTD 24.08.2025Extract Code (Longer)Add Column β†’ Text After Delimiter β†’ β€œNO ” then Before ” FOR”ACLG2402516

Excel Alternatives (for comparison; use FIND for dynamic positions):

Original TextExcel 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)ACLG2402516A-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)ACLG2402516A-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)

OperationBeforeAfterUse Case
Capitalize Each Wordmr. john doeMr. John DoeNames
Uppercasesales repSALES REPCodes
LowercaseProFessioNalprofessionalConsistency
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

ComponentResultDAX/PQ Function
Year1965Date.Year([BirthDate])
Month4Date.Month([BirthDate])
Month NameAprilFormat([BirthDate], "MMMM")
QuarterQ2Date.Quarter([BirthDate])
Day8Date.Day([BirthDate])
Day of WeekMondayDate.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)

BirthDateSystem Date (Ex: Nov 3, 2025)AgeInDaysAgeInYears (Rounded)
1980-05-152025-11-0316,52045
1995-12-012025-11-0310,94530

Real-Time: Uses Control Panel date.
Use Case: Customer master analysis, e.g., age groups (Young/Middle/Senior) for segmentation.


πŸ”’ Number Transformations

CategoryOptions
RoundingRound, Up, Down
Scientific1.23E+10
StatisticsSum, Avg, Min, Max (on selection)
TrigonometrySin, 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

DoDon’t
Use Transform over Add ColumnCreate 10+ duplicate columns
Delete unnecessary stepsKeep raw import columns
Rename everythingRely on Column1, Column2
Test with 100 rows firstTransform full 1M rows

Golden Rule:
Fewer steps = Faster refresh = Happier users


πŸ“ˆ Next Session: Power Query Level 2

TopicDetails
Merge QueriesVLOOKUP on steroids
Append QueriesStack tables (union)
Folder ConnectionAuto-combine 100+ files
Conditional LogicIf-then-else columns
Error HandlingReplace, remove, fill

❓ Q&A Expanded

Q: Power Query vs Excel Data Cleaning?

FeatureExcelPower Query
Split by multi-charβŒβœ…
Auto M-codeβŒβœ…
Reusable stepsβŒβœ…
Handle 1M+ rowsSlowFast

Q: Merge like VLOOKUP?
β†’ Yes! Merge Queries = Left Join
β†’ Covered in Data Modeling


🎯 Final Summary

ConceptKey CommandPurpose
ConnectGet DataImport raw
CleanTrim, CleanFix text
SplitBy DelimiterBreak columns
ExtractText.RangeSubstrings
CalculateCustom ColumnMath logic
AgeDuration.DaysDynamic 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