List.TransformMany

List

Projects each element of a list to a collection, then applies a result transformation to each (original element, projected element) pair. Similar to SelectMany / flatMap.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

List.TransformMany(list as list, collectionTransform as function, resultTransform as function) as list

Parameters

NameTypeRequiredDescription
listlistYesThe source list.
collectionTransformfunctionYesA function that takes an item from the source list and returns a list (the projected collection for that item).
resultTransformfunctionYesA function that takes two arguments — the original item and each projected collection item — and returns the final result value.

Return Value

listA flat list of results produced by applying resultTransform to each pair of (original item, projected collection item).

Remarks

List.TransformMany is the M equivalent of SelectMany (LINQ) or flatMap in functional programming. It is used to expand each item in a list into a sub-collection, then flatten all those sub-collections into a single output list while optionally combining each source item with each projected item.

The function performs a two-stage transformation:

1. collectionTransform: Applied to each item in list, returning a list (the projected sub-collection for that item). 2. resultTransform: A function of two arguments — (originalItem, subItem) — that produces the final output value for each pair.

If collectionTransform returns an empty list for a source item, no output rows are generated for that item (it is effectively filtered out). The output list length equals the sum of the lengths of all projected sub-collections.

This function enables cartesian products, nested data expansion, and one-to-many joins within a list context. It is more powerful than a nested List.Combine(List.Transform(...)) because the resultTransform gives you access to the parent item during the final projection.

Examples

Example 1: Cross-join two lists (cartesian product)

let
    Colors = {"Red", "Blue"},
    Sizes = {"S", "M", "L"},
    Combinations = List.TransformMany(
        Colors,
        each Sizes,
        (color, size) => color & "-" & size
    )
in
    Combinations
Applied Steps

The final output — a flat list of all six color-size combinations.

Result
1{Red-S, Red-M, Red-L, Blue-S, Blue-M, Blue-L}

Example 2: Expand a list of numbers into their factors

let
    Numbers = {4, 6},
    Expanded = List.TransformMany(
        Numbers,
        each List.Numbers(1, _),
        (n, factor) => Text.From(n) & ":" & Text.From(factor)
    )
in
    Expanded
Applied Steps

The final output — a flat list of "number:factor" strings for each number expanded through its full sequence.

Result
1{4:1, 4:2, 4:3, 4:4, 6:1, 6:2, 6:3, 6:4, 6:5, 6:6}

Example 3: Flatten nested lists with context

let
    Departments = {[Dept="Sales", Members={"Alice","Bob"}], [Dept="IT", Members={"Carol"}]},
    Flattened = List.TransformMany(
        Departments,
        each _[Members],
        (dept, member) => dept[Dept] & " - " & member
    )
in
    Flattened
Applied Steps

The final output — a flat list of department-member strings, with each member prefixed by their department name.

Result
1{Sales - Alice, Sales - Bob, IT - Carol}

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks