Type.ForFunction

Type

Creates a function type from a signature record and minimum parameter count.

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

Syntax

Type.ForFunction(signature as record, min as number) as type

Parameters

NameTypeRequiredDescription
signaturerecordYesA record with ReturnType (a type) and Parameters (a list of records with Name, Type, and optional Description).
minnumberYesThe minimum number of required parameters.

Return Value

typeA function type matching the specified signature.

Remarks

Type.ForFunction constructs a function type from a descriptive record. The signature record has two fields:

- ReturnType — the return type of the function. - Parameters — a list of records, each with Name (text), Type (type), and optionally Description (text).

The min parameter specifies how many of the parameters are required. Parameters beyond min are treated as optional.

This function is typically used with Function.From to create dynamically typed custom functions, or with Value.ReplaceType to add parameter metadata to an existing function so it renders properly in the Power Query UI.

### Typical pattern

``powerquery let Signature = [ ReturnType = type text, Parameters = { [Name = "input", Type = type text, Description = "The input text"], [Name = "prefix", Type = type text, Description = "Optional prefix"] } ], FnType = Type.ForFunction(Signature, 1) // 1 required, 1 optional in FnType ``

Examples

Example 1: Create a function type and verify it

let
    Signature = [
        ReturnType = type number,
        Parameters = {
            [Name = "a", Type = type number],
            [Name = "b", Type = type number]
        }
    ],
    FnType = Type.ForFunction(Signature, 2),
    IsFunction = Type.Is(FnType, type function)
in
    #table({"Description", "IsFunction"}, {{"type function (a as number, b as number) as number", IsFunction}})
Result
Description
IsFunction
1type function (a as number, b as number) as numberTRUE

Compatibility

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