Logo

dev-resources.site

for different kinds of informations.

Power Query Data transformations - getting started... quickly

Published at
12/2/2024
Categories
powerplatform
powerbi
powerquery
Author
kkazala
Categories
3 categories in total
powerplatform
open
powerbi
open
powerquery
open
Author
7 person written this
kkazala
open
Power Query Data transformations - getting started... quickly

If you have never worked with Power Query before, check additional resources at the bottom of the page.

Power Query is a powerful data connection, cleaning, and shaping technology that can be used in Excel and Power BI alike. The content retrieved from external sources is transformed using Power Query M language, which offers a set of functions for working with tables, lists, dates, etc.

When adding steps using User Interface, Power Query Editor will automatically add and configure steps. You can edit them instead of adding new step correcting the results.

Update generated steps

Selecting columns

When selecting columns from a data source, the generated step will use Table.SelectColumns function. If the column you defined is missing, you will receive an error and the query will fail. Adding UseNull ensures that the query will execute successfully and the values in the missing column will be set to null.

Image description

Expanding columns

If you expand multiple columns, the new column names will be predefined:

predefined column names

Instead of renaming them in the following step, edit the Table.ExpandTableColumn formula.

Updated formula

Taking a sneak-peek

When working with lists or table column types, you may take a sneak-peek by clicking within the cell, next to the value. The data preview will be displayed at the bottom of the window.

Preview cell  contents

Merging steps

When renaming multiple columns, the Power Query editor will automatically merge them into one step. In some cases, however, separate steps are added.

For example, if you want to replace multiple text occurrences using UI

Image description

multiple steps will be generated.

Image description

I like copying formula of the step above into the step below to merge text transformations into one step.

Step Replaced a with A:

Step1

Step Replaced b with B

Step 2

I update the Replaced b with B to replace a reference to Replaced a with A with its formula:

Image description

After deleting the no longer needed step Replaced a with A and renaming step Replaced b with B, my transformations are much more readable.

Image description

Working with functions

In case you are applying the same transformation to multiple columns, you may want to save them as a function, instead of copying the formula over, and updating it in multiple steps.

Functions scoped to a query

To create a new private function, open Advanced Editor, declare a new function, define input parameters, and copy the transformations from the step. I personally like defining functions at the very beginning, above the source.

Image description

Update the function body to use parameters instead of hardcoded parameters

Image description

And replace the formula in the step

Image description

You will now see your function above the "Source" step. The navigation step is now renamed to an ID, but you can rename it.

Reusable functions

Functions defined in the scope of a Query are private for this query. To define global functions that can be reused, create a new blank query and paste the copied code to the formula.

Image description

Rename it to something representative of the actions it executes:

Image description

You can now use it in the query steps, just like the local functions you referenced before.

Image description

For more information about Power Query M functions, see Understanding Power Query M functions

Parameters

When referencing the step in the Power Query M functions, the data provided by previous steps is of type table.

For more details on accessing values of list or table items, see Item Access. If the column name is provided as parameter, you may use Record.Field (Record functions)

Passing current cell as parameter:

Image description

Passing current row as parameter using _:

Image description

Image description

Make sure that for any cells that may have null value, you define the corresponding parameter as nullable:

Image description

For more information about Power Query M types, see Types.

Best kept secret

To access all functions directly from your Power Query editor, create new blank query and in Advanced Editor type = #shared

Image description

The result:

Image description

After clicking next to the Function, you will see its documentation, along with usage example.

Image description

And clicking on the Function will allow you to test it:

Image description

Source: Data Preparation in Power BI By Reza Rad

Additional resources

⭐ You will find the Power Query M functions used in my Power Platform cost optimization dashboard in the Power BI functions gist

powerbi Article's
30 articles in total
Favicon
How to Become a Power BI Developer in 2025 ?
Favicon
Why Data Visualization Is Important in 2025
Favicon
[Boost]
Favicon
Reducing Energy Costs with Advanced Analytics in Power BI
Favicon
DAX in Power BI- getting started... quickly
Favicon
📊Power BI: Fórmulas Dax e Medidas
Favicon
Is Power BI easy to learn?
Favicon
A Beginner's Guide to Learning Power BI the Right Way
Favicon
Executive Power BI Dashboard: Streamlining Data-Driven Decision Making
Favicon
Power Query Data transformations - getting started... quickly
Favicon
Power BI Measure vs. Column: When to Use Measures and Columns in Your Data Model
Favicon
Power BI Import vs. Direct Query: Understanding the Pros and Cons of Each Data Connection Mode
Favicon
Evento De Power BI Gratuito Com Certificado Da d (ia) 
Favicon
Power BI Embedded Pricing: A Complete Guide to Understanding the Costs and Benefits for Developers
Favicon
Power BI Conditional Formatting: Enhancing Your Visuals with Conditional Formatting
Favicon
Power BI IF Statement: Advanced Conditional Logic with the IF Statement in Power BI
Favicon
Mastering DAX in Power BI: A Beginner’s Guide
Favicon
Power BI Certification: Steps to Getting Certified and Advancing Your Career
Favicon
Power BI Incremental Refresh: Optimizing Performance with Incremental Refresh in Power BI
Favicon
Power BI Healthcare Dashboard: A Game Changer in Medical Data Visualization
Favicon
📊Power BI: Dashboard Básico
Favicon
Guide: How to add Write-Back capabilities to Power BI reports with Power Apps — Part 2
Favicon
Power BI Mobile Mastery: Crafting Responsive Dashboards for Smartphones and Tablets
Favicon
Power BI Course Training in Bangalore: Empower Your Data Skills with NearLearn
Favicon
Power BI KPI Dashboard Examples: Building Dashboards with KPIs That Drive Business Results
Favicon
Microsoft Power BI Consulting & Development Services
Favicon
Power BI KPI Visual: How to Create and Use KPIs in Power BI
Favicon
Power BI New Slicer: Exploring the New Slicer Features in Power BI
Favicon
Row Level Security in Microsoft Fabric — Update: No need for Tabular Editor!
Favicon
📊Power BI: Introdução

Featured ones: