Power Query List.TransformMany: Step-by-Step Guide
In this article
List.TransformMany takes a list, applies a function to each item to produce a new list, then applies a second function to combine each original item with each element of its generated list. The result is a flat list of transformed combinations. You need Power Query available (Excel, Power BI, or Analysis Services) and a basic understanding of M code and lists. The function signature is List.TransformMany(list as list, collectionTransform as function, resultTransform as function, optional equationCriteria as any) as list. The first function returns a list for each item; the second receives the original item and one element from that list and returns the final value.
What You'll Need
- Power Query Editor in Excel (Data > Get & Transform Data) or Power BI Desktop (Transform data). Menu labels can differ slightly by version, device, or region.
- A query with a list column or a list value to work on.
- Familiarity with the Power Query formula bar and the Advanced Editor (View > Advanced Editor).
- Basic M code knowledge: how to write a function with
eachand the underscore_placeholder.
Step-by-Step
- Open the Power Query Editor. In Excel, select your data and choose Data > Get & Transform Data > From Table/Range. In Power BI, use Home > Transform data. The exact path may vary slightly by version.
- Create or identify a list column. You need a column where each cell contains a list. If you don't have one, you can create it with a custom column. For example, add a custom column with formula
= {1..3}to create a list of numbers 1, 2, 3 in every row. Or useText.Split([Column], ",")to turn a delimited text field into a list. - Decide your two transformations. The first function (collectionTransform) must return a list for each item. The second function (resultTransform) receives the original item and one element from that list, and returns the final output. For example, if you have a list of numbers and want to pair each number with its double and triple, your first function could return
{2, 3}for each number, and your second function could multiply the original number by each multiplier. - Write the List.TransformMany formula. In the formula bar or Advanced Editor, use a pattern like:
List.TransformMany( SourceList, each {2, 3}, (original, multiplier) => original * multiplier )Here,SourceListis your list,each {2, 3}is the collectionTransform (returns a list of multipliers for each item), and the resultTransform multiplies the original by each multiplier. The output is a flat list: for each original item, you get two results. - Apply it as a custom column or a new query step. To use it on a column, add a custom column with a formula like:
List.TransformMany([ListColumn], each {1, 2}, (x, y) => x * y)This returns a list in each row. You can then expand the list column to new rows (click the expand icon and choose Expand to New Rows). - Check the result. The output is a list. If you used it in a custom column, each cell contains a list. Expand it to see the values. If you used it as a standalone step, the step value is a list you can preview in the formula bar or by converting to a table.
- Handle errors. If the collectionTransform returns something that is not a list, you will get an error. Ensure it returns a list, even if it's an empty list
{}. The resultTransform must accept two arguments; usingeachwith a single underscore will not work because it only receives one argument. Use an explicit function with two parameters, as shown. - Use equationCriteria if needed. The optional fourth argument is used for equality comparisons when the function needs to match items. In most cases you can omit it. If you need custom comparison, provide a comparer function. This is advanced and rarely needed.
Common Mistakes
- Using
eachfor the resultTransform.eachonly provides one argument (the underscore). List.TransformMany's resultTransform requires two arguments: the original item and the current element from the generated list. Use(x, y) => ...instead. - Returning a single value instead of a list from collectionTransform. The first function must return a list. If you return a number or text, you'll get an error. Wrap it in braces:
{value}. - Forgetting to expand the resulting list column. If you use List.TransformMany in a custom column, the column contains lists. You must expand it to see the final values as rows.
- Confusing the order of arguments. The first function is applied to each item to produce a list; the second function receives the original item and an element from that list. Mixing them up gives wrong results.
- Assuming it flattens nested lists automatically. It does flatten the generated lists into one list, but the resultTransform output is not further flattened. If resultTransform returns a list, you get a list of lists.
Tips
- Use List.TransformMany when you need a Cartesian product-like expansion: each item generates multiple outputs.
- Test your functions separately. Create a small query with a list like
{1,2,3}and apply List.TransformMany to see the output before using it on a column. - Use the Advanced Editor to write multi-line formulas for readability.
- Remember that the result is a flat list, not a table. Convert it to a table with
Table.FromListif needed. - If you need to keep the original item alongside each generated value, have resultTransform return a record:
(x, y) => [Original = x, Generated = y], then expand the records.
Troubleshooting
If you get an error saying "We cannot convert a value of type ... to type List", check that your collectionTransform returns a list. If you get "The field '...' of the record wasn't found", you may be referencing a column that doesn't exist. If the result is empty, ensure your source list is not empty and your functions return values. If the output has more rows than expected, check that your collectionTransform isn't returning a list with many elements. To debug, break the formula into steps: first create a column with the collectionTransform output, then apply the resultTransform manually. If you used each and got an error about arguments, switch to an explicit two-parameter function. If you see "Expression.Error: The name '...' wasn't recognized", check for typos in function names or variable names. Always test on a small sample before applying to large data.
Frequently Asked Questions
What is the difference between List.Transform and List.TransformMany?
List.Transform applies a function to each item and returns one output per item (same length). List.TransformMany applies a function that returns a list per item, then combines each original item with each element of that list, producing a flat list that can be longer than the input.
Can List.TransformMany return a table?
No, it always returns a list. You can convert the list to a table using Table.FromList or Table.FromRecords if your list contains records.
How do I use List.TransformMany with a column in a table?
Add a custom column with a formula like List.TransformMany([MyListColumn], each {1,2}, (x,y) => x*y). This creates a list in each row; then expand the column to new rows to see the values.
Why does my resultTransform need two arguments?
Because it receives both the original item from the source list and the current element from the generated list. This lets you combine them, for example to multiply or concatenate.
Is equationCriteria required?
No, it's optional. It's used for custom equality comparisons when the function needs to match items, which is rare in typical transformations.
Can I use List.TransformMany on multiple lists at once?
No, it operates on a single list. To combine multiple lists, you can nest calls or use other functions like List.Zip or List.Combine.