Yes, Power BI allows you to create custom M functions in Power Query, enabling modular, reusable, and maintainable data transformation logic across multiple queries. This is especially useful when you have repetitive transformation steps that need to be applied to multiple datasets or columns.
How to Create a Custom M Function
-
Write a Function Using the let...in Syntax
Use the following structure to define your function in a new blank query:
let
CleanData = (inputTable as table) as table =>
let
RemovedNulls = Table.SelectRows(inputTable, each [Column1] <> null),
ChangedTypes = Table.TransformColumnTypes(RemovedNulls, {{"Column1", type number}})
in
ChangedTypes
in
CleanData
This defines a function CleanData that removes nulls from Column1 and changes its type to a number.
CleanData(SourceTable)