Record.FieldCount

D

T

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

What is M?

M is the programming language used in Power Query. It’s a functional language, meaning that it emphasizes the evaluation of expressions and avoids changing state or mutating data. This makes it well-suited for working with large datasets, as it allows for efficient processing and manipulation of data.

Understanding Records

Before we dive into the specifics of Record.FieldCount, it’s important to understand what a record is. In M, a record is a data structure that consists of a set of named fields. Each field has a name and a value, and records can be nested inside other records.

For example, consider the following record:


[

CustomerName = “John Smith”,

Orders = [

OrderID = 1,

Product = “Widget”,

Quantity = 5

]

]


This record has two fields: CustomerName and Orders. The Orders field is itself a record with three fields: OrderID, Product, and Quantity.

Using Record.FieldCount

Now that we understand what a record is, let's look at how Record.FieldCount works. This function takes a record as its argument and returns the number of fields in that record.

For example, suppose we have the following record:


[

CustomerName = “John Smith”,

Orders = [

OrderID = 1,

Product = “Widget”,

Quantity = 5

]

]


We can use Record.FieldCount to determine how many fields are in this record:


Record.FieldCount([

CustomerName = “John Smith”,

Orders = [

OrderID = 1,

Product = “Widget”,

Quantity = 5

]

])


This would return the value 2, since there are two fields in this record: CustomerName and Orders.

In summary, the M function Record.FieldCount is a useful tool for working with records in Power Query. By understanding the M language and how records work, you can use this function to efficiently manipulate and analyze large datasets.

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

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)