How to Write a List of Objects in Power Query

Abstract: Resolve Power Query syntax errors by correctly using square brackets to create a list of records instead of invalid curly brace structures.

Created: 2026-10-17 by
Power Query uses square brackets to create lists and curly braces for records. To build a list of objects, you must combine these structures correctly using the record constructor syntax within a list literal. This approach ensures your data is properly typed and compatible with subsequent transformation steps in Power BI or Excel.

Understanding M Language Syntax

In the M language used by Power Query, data types are strictly defined. A common mistake is confusing the syntax for collections with the syntax for individual data structures. You cannot use curly braces {} to define a list; that syntax is reserved for records. Conversely, square brackets [] define a list. Understanding this distinction is critical because Power Query will throw a formula error if you attempt to iterate over a structure it does not recognize as a list.

A record is an unordered collection of fields, similar to a JSON object or a dictionary in other languages. It is defined using curly braces. For example, a single record representing a user might look like this:

{ Name = "John", Age = 30 }

A list is an ordered collection of values. It is defined using square brackets. To create a list of objects, you are essentially creating a list where each element is a record. The correct syntax involves placing multiple record definitions inside square brackets, separated by commas.

Creating a List of Objects Step-by-Step

The most straightforward way to write a list of objects is using the list constructor. This method is ideal when you have a known set of items and want to generate them directly in the Advanced Editor without loading external data sources. Follow these steps to construct your data structure:

  1. Open the Advanced Editor: In Power BI Desktop or Excel, go to the Home tab and click on Advanced Editor. This allows you to view and edit the raw M code behind your query.
  2. Define the Records: Create each individual object using curly braces. Ensure each field has a unique name within the record. For instance, define a record for an employee with properties like ID, Name, and Department.
  3. Wrap in Square Brackets: Enclose all the record definitions within square brackets [ ]. Separate each record with a comma. This tells Power Query that you are building a list, not a single complex record.
  4. Assign to a Variable: Use the = operator to assign this list to a variable name, such as MyList.

Here is a complete, syntactically correct example of a list containing three employee records:

let
    Source = [
        { EmployeeID = 1, Name = "Alice", Dept = "Sales" },
        { EmployeeID = 2, Name = "Bob", Dept = "IT" },
        { EmployeeID = 3, Name = "Charlie", Dept = "HR" }
    ]
in
    Source

Note that in the final output, the variable Source holds a list of three records. If you were to expand this column later, Power Query would automatically split these records into separate columns for EmployeeID, Name, and Dept. This pattern is frequently used when you need to merge static configuration data with dynamic query results, a process that often intersects with tasks like Column Rename Excel File Not Reflecting in PowerBI, where structural integrity of the source data is paramount.

Common Syntax Errors to Avoid

Developers often encounter errors because they mix up the delimiters. One prevalent error is writing { record1, record2 }. This creates a record with two fields named after the first and second elements, rather than a list of two records. Another error is forgetting the commas between records, which causes a parsing failure. Always ensure that every record inside the list is terminated by a comma, except for the very last one.

Additionally, be careful with field names. If a field name contains spaces or special characters, you must enclose it in quotes or use the double-quote syntax within the record definition, though standard alphanumeric names do not require quoting. For example, { "First Name" = "John" } is valid, but { First Name = "John" } will fail unless you escape it properly. This precision is necessary because Power Query is case-sensitive and strict about identifiers.

Converting Lists to Tables

Once you have successfully created a list of objects, the next logical step is usually to convert it into a table for analysis. Power Query provides a built-in function called Table.FromRecords specifically for this purpose. By passing your list variable to this function, Power Query iterates through each record in the list and promotes the field names to column headers.

let
    MyList = [
        { ID = 1, Value = "A" },
        { ID = 2, Value = "B" }
    ],
    ConvertedTable = Table.FromRecords(MyList)
in
    ConvertedTable

This conversion is highly efficient and preserves the data types inferred from the values. If you find yourself needing to summarize or aggregate this new table, you might explore techniques for Summarizing max. values for each row in an excel table, which often follows the initial data structuring phase.

Using List.Generate for Dynamic Lists

While static lists are useful, you may sometimes need to generate a list of objects dynamically based on a condition. The List.Generate function allows you to create such lists programmatically. Unlike some lazy evaluation models in other languages, M evaluates expressions eagerly in many contexts, but List.Generate controls the iteration logic explicitly. You provide four functions: one to initialize the state, one to determine if the loop should continue, one to calculate the next value (the record), and one to update the state.

For example, generating five records with incrementing IDs can be done as follows:

let
    Source = List.Generate(
        () => [i = 1],
        each [i] <= 5,
        each [i = [i] + 1],
        each [Record = [i]]
    ),
    Result = Table.FromRecords(Source)
in
    Result

This approach is powerful for creating test data or filling gaps in datasets. However, remember that List.Generate returns a list, so you still need Table.FromRecords to make it tabular. If you are working with complex data relationships, understanding how to handle these generated structures can prevent issues similar to those described in Excel Formula to group similar values, where grouping logic depends on precise data formatting.

Frequently Asked Questions

Can I mix different types of objects in a Power Query list?

Yes, Power Query lists are untyped, meaning you can store records, numbers, text, and even nested lists in the same collection. However, mixing types can complicate downstream transformations like Table.FromRecords, which expects all elements to be records with consistent fields. It is best practice to keep lists homogeneous to avoid type mismatch errors during expansion.

How do I add a new object to an existing list in Power Query?

You can concatenate lists using the & operator. To add a new record, simply append it to your existing list variable. For example, MyList & { NewRecord = "Value" } creates a new list containing all original items plus the new one. This immutable approach aligns with functional programming principles inherent in the M language.

What happens if I forget the comma between records?

Power Query will return a syntax error indicating an unexpected token. The parser expects a comma to separate elements in the list literal. Without it, the engine cannot distinguish where one record ends and the next begins. Always review the comma placement carefully, especially when copying and pasting record definitions.

Is there a performance difference between creating lists manually vs. using List.Generate?

For small datasets, the difference is negligible. However, List.Generate can be more memory-efficient for large sequences because it generates items on demand rather than holding all items in memory at once before processing. For typical business intelligence workloads involving thousands of rows, both methods perform well, but List.Generate offers greater flexibility for conditional generation.

How can I debug a list of objects that isn't expanding correctly?

Use the Value.Type function to inspect the structure of your list elements. You can also expand the list column in the UI to see if all records have the same fields. If some records are missing fields, the expansion will result in null values for those positions. Ensuring uniform schema across all records in the list prevents unexpected nulls in your final table.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More