In this guide, we will be looking at the detailed guide on Power Query in Power BI with implementing steps and examples of it
Power Query in Power BI is a powerful ETL (Extract, Transform, Load) tool that allows users to connect, clean, and transform data before loading it into Power BI for analysis and visualization.
This guide provides a detailed overview of Power Query’s features, step-by-step instructions on using it, and examples to illustrate its capabilities.
Related Article: What is KPI in Power BI? – Comprehensive Guide
What is Power Query?
Source: Microsoft Power BI
Power Query is an intuitive data transformation and data preparation tool integrated into Power BI. It enables users to:
- Connect to a wide range of data sources.
- Clean and transform data using a user-friendly interface.
- Load transformed data into Power BI for further analysis.
Key Features of Power Query
- Data Connectivity: Connect to multiple data sources including databases, web services, and various file formats.
- Data Transformation: Apply various transformations such as filtering, sorting, merging, and pivoting data.
- User Interface: An easy-to-use graphical interface that allows users to perform transformations without writing code.
- M Language: For advanced users, Power Query offers the M language for complex transformations.
Steps for Power Query in Power BI
Step 1: Accessing Power Query
- Open Power BI Desktop: Launch Power BI Desktop to start working with Power Query.
- Get Data: Click on the “Home” tab and select “Get Data”. This opens a window where you can choose your data source.
Step 2: Connecting to a Data Source
- Select a Data Source: Choose a data source such as Excel, SQL Server, or a web page. For example, select “Excel” to connect to an Excel file.
- Load Data: Navigate to the file location and select the file. Click “Load” to import the data into Power Query Editor.
Step 3: Using Power Query Editor
Once the data is loaded, Power Query Editor opens. Here, you can perform various data transformations.
- Preview Pane: View a sample of the data to understand its structure.
- Query Settings: The right pane shows the applied steps and properties of the query.
- Ribbon: The top menu offers various transformation options.
Step 4: Performing Data Transformations
1. Removing Columns
- Select Columns: Click on the columns you want to remove.
- Remove Columns: Go to the “Home” tab and click “Remove Columns”.
2.Filtering Rows
- Select Column: Click on the column header you want to filter.
- Apply Filter: Click the dropdown arrow in the column header, choose the filter criteria (e.g., “Greater than 1000”), and apply.
3. Splitting Columns
- Select Column: Click on the column you want to split.
- Split Column: Go to the “Transform” tab, select “Split Column”, and choose the delimiter or number of characters.
4. Merging Queries
- Merge Queries: Go to the “Home” tab, click “Merge Queries”, and select the queries you want to merge.
- Join Type: Choose the type of join (e.g., Inner Join, Left Outer Join).
5. Grouping Data
- Group By: Go to the “Transform” tab, click “Group By”, and select the column(s) to group by.
- Aggregation: Choose the aggregation method (e.g., Sum, Average).
Step 5: Advanced Transformations Using M Language
For complex transformations, you can use the M language.
Example: Adding a Custom Column
- Custom Column: Go to the “Add Column” tab and click “Custom Column”.
- Write M Code: In the formula box, write your M code. For example, if [Sales] > 1000 then “High” else “Low”.
Step 6: Loading Data into Power BI
- Close & Apply: Once you’ve finished transforming the data, click “Close & Apply” in the Power Query Editor.
- Data Load: The transformed data is loaded into Power BI for further analysis and visualization.
Practical Examples of Power Query
Example 1: Combining Data from Multiple Excel Sheets
- Connect to Excel: Import data from multiple sheets within an Excel file.
- Append Queries: Use “Append Queries” to combine the data from different sheets.
- Clean Data: Apply necessary transformations like removing unnecessary columns and filtering rows.
- Load Data: Load the combined and cleaned data into Power BI.
Example 2: Extracting Data from a Web Page
- Connect to Web Data: Select “Web” from the “Get Data” options and enter the URL of the webpage.
- Select Tables: Choose the table containing the data you need.
- Transform Data: Apply transformations such as renaming columns, changing data types, and filtering rows.
- Load Data: Load the transformed data into Power BI.
Example 3: Data Integration from Multiple Sources
Objective: Combine data from a SQL Server database and an Excel file.
- Connect to SQL Server: Select “SQL Server” from “Get Data” and provide the server and database name. Import the required table.
- Connect to Excel: Select “Excel” from “Get Data” and import the necessary sheet.
- Merge Queries: In the Power Query Editor, use “Merge Queries” to combine the SQL data with the Excel data. Choose the appropriate join type and matching columns.
- Transform Data: Apply transformations such as renaming columns, changing data types, and filtering rows.
- Load Data: Load the combined and transformed data into Power BI.
Example 4: Extracting and Transforming JSON Data
Objective: Extract data from a JSON API and transform it for analysis.
- Connect to Web: Select “Web” from “Get Data” and enter the API URL.
- Parse JSON: Once the data is loaded, click on the “Record” or “List” to navigate through the JSON hierarchy.
- Expand Data: Use the “Expand” option to flatten the JSON structure into a tabular format.
- Transform Data: Apply necessary transformations like renaming columns, filtering rows, and changing data types.
- Load Data: Load the transformed data into Power BI for further analysis.
Best Practices in Power Query
- Plan Transformations: Outline the steps required before starting the transformation process.
- Descriptive Naming: Use meaningful names for queries and steps for better readability.
- Minimize Steps: Combine multiple transformation steps to improve performance.
- Regular Updates: Regularly update queries to accommodate changes in the data source.
Conclusion
Power Query in Power BI is an essential tool for efficient data preparation and transformation.
Its user-friendly interface, combined with powerful capabilities, makes it accessible to both novice and advanced users.
By following this guide and leveraging Power Query’s features, you can streamline your data workflows and enhance your data analysis capabilities in Power BI.
Meet Nitin, a seasoned professional in the field of data engineering. With a Post Graduation in Data Science and Analytics, Nitin is a key contributor to the healthcare sector, specializing in data analysis, machine learning, AI, blockchain, and various data-related tools and technologies. As the Co-founder and editor of analyticslearn.com, Nitin brings a wealth of knowledge and experience to the realm of analytics. Join us in exploring the exciting intersection of healthcare and data science with Nitin as your guide.