All Content
Timespan
explore our new search
Power Query: Using M Functions – List.Dates & Date.Add
Power BI
Apr 7, 2023 6:00 PM

Power Query: Using M Functions – List.Dates & Date.Add

by HubSite 365 about Pragmatic Works

Data AnalyticsPower BILearning Selection

In this video, Angelica will show you how to quickly create a single-column Date table using the M Query function List.Dates.

In this video, Angelica will show you how to quickly create a single-column Date table using the M Query function List.Dates. Then, she will briefly demonstrate how you can use the functions Date.AddMonths and Date.AddWeeks to create a range of new columns based on the conditions you specify.

What is the M function?

M functions are user-defined functions in Power Query, a data transformation and data preparation tool that is part of Microsoft Excel and Power BI. M functions are created using the M language, which is a functional programming language that is used to define queries in Power Query.

M functions allow users to create reusable code blocks that can be used to perform specific data transformations or tasks. These functions can be shared with others or reused in other queries, which can save time and improve efficiency when working with data.

To create an M function in Power Query, you can use the “New Source” dialog and select “Blank Query” or “Blank Query with Current Connection”. Then, in the formula bar, you can define the function by using the “let” keyword followed by the function name and the function body. The function body contains a series of steps that perform the desired data transformation or task.

For example, the following M function takes a table as input and returns a new table that is sorted by the values in a specific column:

vbnet

let sortTable = (inputTable as table, sortColumn as text) => Table.Sort(inputTable, {{sortColumn, Order.Ascending}}) in sortTable

Once the function is defined, you can call it from other queries by referencing the function name and passing in the required parameters.