Quantcast
Channel: Cloud Training Program
Viewing all articles
Browse latest Browse all 1890

What is Power Query | Microsoft Azure Power BI Tool

$
0
0

This blog post is going to cover all necessary information about Power Query – one of the important and powerful tools in Microsoft Azure Power BI Service.

When using Power BI, we unknowingly use Power Query features for importing data and transforming it for further use. This blog will give a niche view of Power Query and discuss more of its functionalities.

Note: If you are not familiar with Power BI, its purpose, advantages, terminologies, and related career roles then check Introduction to Microsoft Power BI Platform | Everything You Must Know

This blog post is going to cover:

What Is Power Query?

Power Query is a powerful Power BI tool that takes care of Power BI operations in locating, connecting, and loading diversified data across various sources. It also shapes and transforms the imported data so that it can be used to create visuals. It is also referred to as a self-service ETL tool in Power BI since it is self-sufficient to extract, load, and also transform data. It can be accessed in Power BI Desktop by going to the Get Data option in the Home Menu.

 Advantages Of Power Query

There are many advantages of Power Query that makes it a preferred choice of many BI reporters or Analysts:

  • Free of Cost: Power Query is available as a free tool service in Power BI. There is no need for Power BI users to purchase it as an additional add-on or install it from external sources. Simply log in to the Power BI account and use it right away.
  • Vast Data Sources: Power Query supports connection and importing of a huge list of data sources. Some of which include Excel files or workbooks, text or CSV files, files from the cloud or on-premise data storage software.
  • Excel Integration: Power Query is now integrated into Microsoft Excel free for all. This makes it easy for Excel users who can easily shift to Power BI if they want to create beautiful reports after a basic ETL of data.
  • User-friendly: Power Query does not require the user to learn or use pieces of code to perform ETL operations. Power Query Editor, which is the environment for Power Query, provides simple select, drag and click GUI operations to perform the same ETL tasks for users who are not comfortable with coding. Another benefit of this is that the GUI option makes your work go faster and easier.
  • Non-Repetitive Tasks: The greatest advantage of Power Query is, that the users don’t have to re-write/re-perform the same tasks of data operations after an interval of time. This is because all the ETL steps executed in Power Query are stored as query steps in its Editor. To repeat any operation, simply go to and refresh the particular query step. This makes it easier for users to focus on the business logic and worry less about the procedure.
  • M-Language: It is the query language for Power Query to execute tasks of connecting to data, importing and transforming it into data models. It makes it simple to learn and apply as a coding language and performs all operations efficiently. The M Language is a case-sensitive and functional language that consists of ‘let’ and ‘in’ block statements that contain variables, constants and functions like any other language. The output of the queries can be sent to either the Power BI data models pane or to an Excel workbook.

A Glimpse Of Power Query Editor

The Power Query Editor is an environment for us to work with Power Query. Let us have a look into the Power Query Editor and understand its various parts and their purposes.

  • To open the Power Query Editor after logging in to the Power BI Desktop, go to the Get Data option in the Home Menu -> Blank Query

Get Data for Power Query Editor

Since no data has been imported yet, the Power Query Editor opens up being blank. Let us look into the parts the Editor has been divided into:

Power Query Editor

  1. Queries Pane: It shows a list of all the active queries in the project. A query can be seen as a container having multiple steps of data transformation, done with code (M-Language) or the GUI. On selecting any query, its transformed data can be seen in the center pane. Double click on the query tab to change its name or drag them to change their order. You can also do non-repetitive tasks of the query by simply refreshing it, or copy-pasting it into another query.
  2. Formula Tab: This tab will display a short snippet of the latest M-Language commands related to the transformations that were performed on the data in a particular query or the steps within a query. Even if the transformation is made using GUI, the formula tab will show the backend M code snippet that was applied. You can expand the tab to see the entire command.
  3. Query Settings: This section on the right shows all the information of the selected query from the Queries pane. It consists of two sub-sections:
    • Name Section shows the current query name which we are working on
    • Applied Steps keeps showing the transformation steps being performed in the query one after the other. A query step will work on the output of its previous query step in the list. Hence the order of these steps is important. Steps of a query within Applied Steps can be arranged in any order, renamed, and deleted with a right-click on that step. A query will execute as its steps are ordered in the Applied Steps section.

On clicking any query in the Queries pane or its steps in the Applied Steps, the particular modification on the dataset can be seen in the center pane. However, the underlying data is not changed in the Editor, it manages to create views of data according to the selected query or a transformation step within a query.

Importing Data In Power Query Editor

To get more insights on Power Query Editor features, let us load a sample web data into it. We load the web dataset of TechStocks which contains the daily stock prices information of three companies: Apple, Google, and Microsoft. You can download or enter the URL of the dataset to import it here. We import the dataset by providing its URL:

Import Data in Power Query Editor

Our Editor now looks much more active and interactive. The dataset can be seen imported at the center in the Data Pane. Let us study the changes it developed:

Loaded Editor Overview

  1. Queries Pane: A new query tab named TachStocks (name of our dataset) has been formed.
  2. Name section (Query Settings): This shows the query name we are currently into.
  3. Menu: This ribbon shows many functions and operations that we do with our dataset.
  4. Column Names: It shows us the column names in the dataset along with symbols indicating their datatype. It also contains an arrow button to select the entire column and do some column operations.
  5. Applied Steps section (Query Settings): It shows all the transformation steps that were taken place in the query. Although we have performed a simple query of importing our dataset, the Power Editor has automatically performed few query steps for us such as putting the names of the columns as their headers in the original dataset and assigning appropriate data types to all columns.
    • On clicking any of the query steps, we can see a view of the data as an output of the transformation steps applied from the first query step till the selected query step (inclusive)
      Eg. on clicking the step names ‘Promoted Headers‘ we will be able to see the dataset having its headers as column names but with unapplied datatypes on the columns. The ‘Changed Datatype‘ step shows all the query steps done on the data: from its import till its column datatypes changed accordingly.
  6. Formula Tab: When we are on the ‘Changed Datatype‘ step, the tab shows the M-Language equivalent code snippet that was applied in the backend for the transformation to work.

The Advanced Editor

This Editor is the main place to try out your queries in the form of M-Language code. It also shows the code that the Editor is created for a particular query or query step.

  • Click the Advanced Editor button on the Home Menu

You can see the existing code in the Advanced Editor or start writing your own query. In the image below within the Advanced Query Editor, highlighted part of the code is the most recent transformation applied to the dataset which is exactly reflected in the Formula Tab above.
As discussed above, you can see that the M-Language in the Advanced Editor consists of ‘let’ and ‘in’ block statements.

Advanced Text Editor

To close the window, select the Done or Cancel button.

Working With Power Query Editor

Let us transform the dataset a little to further clear our concepts discussed earlier. To create a new query:

  • Right-click below on the gray area of the Queries Pane -> New Query -> Blank Query

Create new Power Query

We use the existing query created earlier (TechStocks) Let us perform simple data transformations and see how Power Query Editor works on them. Execute these operations with the GUI and in order:

  • Sort Data column in descending order
  • Filter AAPL, GOOG and MSFT Columns respectively to remove null value rows

You can see in the Applied Steps, the order of the query steps (we have renamed those steps for your better understanding). It stops on the latest step we applied i.e filtering the MSFT Column. The underlying M code for this latest step is shown in the Formula Tab too.

Transform Data in Editor

Imagine a business environment having real-world messy and huge data, to do vast transformations to build a perfect data model for visualizations. They have to keep a track of queries applied, replicate or backtrack to previous steps and also order similar or logical steps into a single query. This is where the real strength of Power Query can be applied to make the work easy and fast.

Power Query is thus effective in manipulating data and storing all the previous query information to be reused later. Power Query has many more benefits in transforming data with the M-Language to create more powerful and complex data transformations.

Save Changes To Power Query

After performing all operations in Power Query Editor, we need to apply and save changes to the data model in our Power BI Desktop before we exit the Power Query Editor.

  • Go to the File menu in the Editor -> Close & Apply

Save Changes in Editor

This only saves your imported and transformed data in the Data Model button on the left of the Power BI Desktop. When you are satisfied with your data model, you need to save the project as a whole before closing the Power BI Desktop application.

  • Go to File menu -> Save/Save As to save your Power BI Project

This completes our understanding of how Power BI uses Power Query for its ETL process.

Get Certified for Power BI: Microsoft [PL-300]

Microsoft provides Microsoft Certified Power BI Data Analyst Associate [PL-300] Certification which is beneficial for BI/Data Analysts or professionals who are involved in creating BI reports for solving business problems. It endorses your Power BI skills in the market and helps you unlock Power BI to its full potential. This is beneficial since Power BI has vast capabilities to help businesses in creating rich visualizations and data apps that are well tailored for their needs.

References

Next Steps to begin with PL-300 Certification:

In our PL-300 Certification Training Program, we’ll cover 10+ Hands-On Labs. If you wish to start your journey towards becoming a Microsoft Certified: Power BI Data Analyst Associate, try our FREE CLASS.

DA100_CU

 

The post What is Power Query | Microsoft Azure Power BI Tool appeared first on Cloud Training Program.


Viewing all articles
Browse latest Browse all 1890

Trending Articles