[Power Query] What is M Language? A Beginner’s Guide

目次

Introduction

When using Power Query in Excel, you may encounter the unfamiliar term “M Language” (or M Script). At first, I was confused and didn’t know what it meant, but after researching, I realized it is a crucial mechanism that supports the very foundation of Power Query.

In this article, I will explain M Language in a way that is easy to understand, even for those encountering it for the first time.

What is M Language?

M Language (officially known as Power Query M Formula Language) is the script language used inside the Power Query Editor in Excel and Power BI.

All operations performed in Power Query—getting data, transforming it, and shaping it—are processed behind the scenes by this M Language.

Main Features of M Language

Specialized for Data Transformation and Query Processing

M Language is specialized for data transformation tasks such as:

  • Importing external data
  • Filtering
  • Splitting and merging data
  • Aggregation and sorting

Even complex processing can be achieved using M Language.

Functional Programming Language

M Language adopts a “Functional Programming” format, defining data processing as a chain of functions step-by-step. As a result, the flow of processing is intuitive and has a readable structure.

Integration with Power Query UI

In the Power Query Editor, the operations performed by the user (such as deleting columns or filtering) are automatically converted into M Language. Therefore, you usually do not need to write M Language directly. However, if you need to perform specific advanced processing, you can manually edit and customize the M Language code to enable more flexible operations.

Supports Custom Functions and Complex Conditional Logic

Using M Language allows you to easily implement processing such as:

  • Data shaping based on specific conditions
  • Custom aggregation processing (Min, Max, Average, etc.)
  • Expanding nested tables
  • Combining and reworking multiple sources

When Do You Actually Use It?

Do Users Need to Write M Language?

For standard operations, you do not need to be conscious of M Language. However, there are cases where features not provided in the standard Power Query UI or fine-tuned customizations are required. In these instances, directly editing the M Language can solve the problem.

Example: Calculating the Average of a Column If it is difficult to create a column for an average value directly using standard Power Query operations, you can easily handle it by writing a function in M Language to create a custom column.

Summary

M Language is the powerful script language that supports the behavior of Power Query from behind the scenes. While it is not visible during normal operations, it is an essential element for performing data shaping efficiently.

  • All Power Query processing is written in M Language.
  • It supports complex transformations and custom processing.
  • It allows for flexible customization that supplements UI operations.

Knowing even a little of the basics of M Language will significantly expand the range of processing you can master in Power Query.

I hope this article helps you in your Power Query journey. Thank you for reading to the end.

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

私が勉強したこと、実践したこと、してることを書いているブログです。
主に資産運用について書いていたのですが、
最近はプログラミングに興味があるので、今はそればっかりです。

目次