Power Query – Importing and Managing Data: Difference between revisions

From Training Material
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:


== Objective ==
== Objective ==
In this module, you'll learn how to import data from various sources and manage basic data loading settings in Power Query.
Learn how to import data from different sources and manage query settings.


== Files Used ==
== Files Used ==
Line 12: Line 12:
== Importing Data from Excel ==
== Importing Data from Excel ==
'''Steps:'''
'''Steps:'''
# Open Excel
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Workbook...'''
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Workbook...'''
# Select '''Sales_January.xlsx''' and click '''Import'''
# Select '''Sales_January.xlsx'''
# In the Navigator window, select the sheet and click '''Transform Data'''
# In the Navigator window, select the sheet and click '''Transform Data'''
# The data will open in Power Query Editor


== Importing Data from CSV ==
== Importing Data from CSV ==
Line 22: Line 20:
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Text/CSV'''
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Text/CSV'''
# Select '''Employees.csv'''
# Select '''Employees.csv'''
# Review the preview window, then click '''Transform Data''' to load it into Power Query
# Click '''Transform Data'''
 
== Importing from a Text File ==
'''Steps:'''
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Text/CSV'''
# Select '''ProductList.txt'''
# Set delimiter to '''Tab'''
# Click '''Transform Data'''


== Importing Multiple Excel Files ==
== Importing Multiple Excel Files ==
'''Scenario:''' You want to combine all monthly sales files into a single dataset.
'''Scenario:''' Combine monthly files into one dataset.


'''Steps:'''
'''Steps:'''
# Place all monthly files (e.g. Sales_January.xlsx, Sales_February.xlsx) in one folder
# Place '''Sales_January.xlsx''' and '''Sales_February.xlsx''' in the same folder
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Folder'''
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Folder'''
# Browse to the folder containing the Excel files
# Select the folder and click '''Transform Data'''
# Click '''Transform Data'''
# In Power Query Editor: click '''Combine''' → '''Combine & Transform Data'''
# In Power Query Editor:
# Select the worksheet to use and confirm
#* Click '''Combine''' → '''Combine & Transform Data'''
 
#* Select the sheet to combine from each file
== Managing Queries ==
# Power Query will generate a sample query and combine all files into one table
* Rename queries (right-click → '''Rename''')
* Duplicate queries (right-click → '''Duplicate''')
* View query dependencies: '''View''' tab → '''Query Dependencies'''
 
== Import Multiple CSV Files ==
'''Goal:''' Practice folder import using CSVs.


== Importing from a Text File ==
'''Steps:'''
'''Steps:'''
# Go to the '''Data''' tab → '''Get Data''' → '''From File''' → '''From Text/CSV'''
# Save a few copies of '''Employees.csv''' with small changes (e.g. Employees_1.csv, Employees_2.csv)
# Select the file '''ProductList.txt'''
# Place them in a folder
# Choose delimiter: ''Tab''
# Use '''Get Data → From Folder''' to combine them
# Click '''Transform Data''' to edit it in Power Query
# Filter only Active employees
# Load to a worksheet
 
== Create a Parameter for Folder Path ==
'''Goal:''' Make your folder import dynamic so the query works even if the folder path changes.
 
=== 1. Open Power Query Editor ===
If you're not already there:
* In Excel → '''Data''' tab → '''Queries & Connections'''
* Right-click your folder-based query → '''Edit'''
 
=== 2. Create the parameter ===
* In Power Query Editor → '''Home''' tab → '''Manage Parameters''' → '''New Parameter'''
* Fill in:
** Name: `ImportFolder`
** Type: Text
** Current Value: (paste the folder path you used originally)
* Click '''OK'''
 
=== 3. Replace the static path with the parameter ===
 
'''Option A: Source step'''
# In the Applied Steps pane → click ⚙ next to '''Source'''
# Replace the folder path with: `ImportFolder`
# Click '''OK'''
 
'''Option B: Advanced Editor'''
# Go to '''Home''' tab → '''Advanced Editor'''
# Find the line:
Source = Folder.Files("C:\your\original\path")
 
# Replace with:
 
Source = Folder.Files(ImportFolder)
 
# Click '''Done'''


== Managing Queries ==
=== 4. Load the result ===
In Power Query Editor, you can:
* Go to '''Home''' → '''Close & Load To...'''
* Rename queries (right-click query name → '''Rename''')
* Choose whether to create a table, connection, or add to the Data Model
* Disable load (right-click query uncheck '''Enable Load to Worksheet''')
* View query dependencies: go to the '''View''' tab → click '''Query Dependencies'''


== Merging Queries (Preview) ==
=== ✅ Result ===
You’ll later learn how to join data sources together using merges and appends. 
You can now change the folder path in the parameter settings, and the query will update automatically.
For now, make sure you have both Sales and Employees queries loaded.


----
----

Latest revision as of 09:49, 22 June 2025

Module 2: Importing and Managing Data

Objective

Learn how to import data from different sources and manage query settings.

Files Used

Importing Data from Excel

Steps:

  1. Go to the Data tab → Get DataFrom FileFrom Workbook...
  2. Select Sales_January.xlsx
  3. In the Navigator window, select the sheet and click Transform Data

Importing Data from CSV

Steps:

  1. Go to the Data tab → Get DataFrom FileFrom Text/CSV
  2. Select Employees.csv
  3. Click Transform Data

Importing from a Text File

Steps:

  1. Go to the Data tab → Get DataFrom FileFrom Text/CSV
  2. Select ProductList.txt
  3. Set delimiter to Tab
  4. Click Transform Data

Importing Multiple Excel Files

Scenario: Combine monthly files into one dataset.

Steps:

  1. Place Sales_January.xlsx and Sales_February.xlsx in the same folder
  2. Go to the Data tab → Get DataFrom FileFrom Folder
  3. Select the folder and click Transform Data
  4. In Power Query Editor: click CombineCombine & Transform Data
  5. Select the worksheet to use and confirm

Managing Queries

  • Rename queries (right-click → Rename)
  • Duplicate queries (right-click → Duplicate)
  • View query dependencies: View tab → Query Dependencies

Import Multiple CSV Files

Goal: Practice folder import using CSVs.

Steps:

  1. Save a few copies of Employees.csv with small changes (e.g. Employees_1.csv, Employees_2.csv)
  2. Place them in a folder
  3. Use Get Data → From Folder to combine them
  4. Filter only Active employees
  5. Load to a worksheet

Create a Parameter for Folder Path

Goal: Make your folder import dynamic so the query works even if the folder path changes.

1. Open Power Query Editor

If you're not already there:

  • In Excel → Data tab → Queries & Connections
  • Right-click your folder-based query → Edit

2. Create the parameter

  • In Power Query Editor → Home tab → Manage ParametersNew Parameter
  • Fill in:
    • Name: `ImportFolder`
    • Type: Text
    • Current Value: (paste the folder path you used originally)
  • Click OK

3. Replace the static path with the parameter

Option A: Source step

  1. In the Applied Steps pane → click ⚙ next to Source
  2. Replace the folder path with: `ImportFolder`
  3. Click OK

Option B: Advanced Editor

  1. Go to Home tab → Advanced Editor
  2. Find the line:
Source = Folder.Files("C:\your\original\path")
  1. Replace with:
Source = Folder.Files(ImportFolder)
  1. Click Done

4. Load the result

  • Go to HomeClose & Load To...
  • Choose whether to create a table, connection, or add to the Data Model

✅ Result

You can now change the folder path in the parameter settings, and the query will update automatically.


Return to Main Page

→ Continue to Module 3: Data Transformation Techniques