The M Code Behind the Power Query M function Record.TransformFields

Understanding TransformFields

TransformFields is a function in the Power Query M language that allows users to modify the contents of a table by transforming individual fields. This function is particularly useful when working with large data sets that require complex transformations.

To use TransformFields, users must provide two arguments: the table to be transformed, and a function that defines the transformation to be applied to each field. The function takes a single argument, which represents the current value of the field. The function should return the new value of the field.

TransformFields then applies the specified function to each field in the table, returning a new table with the transformed data.

Key Features of TransformFields

The TransformFields function offers a number of key features that make it a powerful tool for data transformation:

Customizable Transformations

One of the most powerful features of the TransformFields function is its ability to apply custom transformations to table data. Users can define their own M code to transform each field in the table, allowing for a high degree of flexibility and customization.

Automatic Detection of Data Types

The TransformFields function automatically detects the data type of each field in the table, allowing users to apply appropriate transformations to each field. This feature makes it easy to work with large and complex data sets that contain multiple data types.

Support for Nested Tables

TransformFields also supports nested tables, enabling users to apply transformations to nested fields and sub-tables within the main table. This feature is particularly useful when working with complex data structures that contain multiple layers of nested data.

Use Cases for TransformFields

TransformFields is a versatile tool that can be used in a variety of data transformation scenarios. Some common use cases include:

Data Cleaning and Standardization

TransformFields can be used to clean and standardize data by applying custom transformations to individual fields. For example, users could use TransformFields to remove leading or trailing whitespace from text fields, or to convert dates to a standardized format.

Data Aggregation and Summarization

TransformFields can also be used to aggregate and summarize data by applying custom functions to fields. For example, users could use TransformFields to calculate the average or maximum value of a field across multiple rows.

Data Filtering and Sorting

TransformFields can be used to filter and sort data by applying custom functions to fields. For example, users could use TransformFields to filter out rows where a field contains a specific value, or to sort rows based on the value of a specific field.

The TransformFields function is a powerful tool that enables users to transform table data using custom M code. Its key features, including customizable transformations, automatic data type detection, and support for nested tables, make it a versatile tool for data transformation and analysis.

Whether you are cleaning and standardizing data, aggregating and summarizing data, or filtering and sorting data, TransformFields can help you achieve your goals. By leveraging the power of M code, you can easily transform even the most complex data sets into valuable insights and actionable information.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

25-27 Sep 23 (London or Online)
20-22 Nov 23 (London or Online)

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)