Functions

M Table Functions

Table Functions

M table functions like Table.AddColumn modify tables.

Introduction to M Table Functions

M table functions are powerful tools in Power Query that allow you to manipulate tables in a variety of ways. Whether you're adding, removing, or transforming columns, these functions provide a flexible approach to managing tabular data. In this guide, we'll explore some common table functions, focusing on Table.AddColumn, and how they can be used to modify tables effectively.

Using Table.AddColumn

The Table.AddColumn function in M is used to add a new column to an existing table. This function requires three parameters: the table to modify, the name of the new column, and a column generator function that defines how the new column's values are calculated.

In the example above, we start with a simple table containing names and ages. We then use Table.AddColumn to add a new column named IsAdult. The values in this column are calculated by checking if the age is 18 or older, returning true or false.

Other Useful M Table Functions

Beyond Table.AddColumn, M provides other functions to manipulate tables:

  • Table.RemoveColumns: Removes one or more columns from a table.
  • Table.RenameColumns: Renames columns in a table.
  • Table.SelectRows: Filters rows based on a condition.
  • Table.TransformColumns: Applies a transformation function to one or more columns.

This code snippet demonstrates the usage of multiple table functions. We start with a table and remove the Name column using Table.RemoveColumns. We then rename the Age column to Years with Table.RenameColumns. Finally, we filter the table to include only rows where Years is 18 or more using Table.SelectRows.

Conclusion

M table functions are essential for data transformation tasks in Power Query. Understanding how to utilize these functions, such as Table.AddColumn, can greatly enhance your ability to work with data. Explore and experiment with these functions to see how they can be applied to your specific data challenges.

Next
Lists