Type.FunctionParameters

Updated on

Type.FunctionParameters is a Power Query M function that extracts a record with the names of the parameters of a given function type and their corresponding types. The function returns a record with the parameter names and types of the input function type.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Type.FunctionParameters( type as type ) as record

Description

Type.FunctionParameters is a function designed to identify and return the parameters of a given function. This function accepts a type as its input and produces a record. In this record, the field names represent the names of the parameters associated with the input type. Additionally, the field values indicate the respective data types of these parameters.

Examples

For instance, the Text.Combine function takes two arguments, one of type list and one of type nullable text. To retrieve those arguments and return them as a record you can use:

// Returns [ texts = list, separator = nullable text ] 
Type.FunctionParameters( Value.Type( Text.Combine ) )

Value.Type first retrieves the type and its characteristics from the Text.Combine function. Type.FunctionParameters then returns the function parameters and their types in the form of a record.

Applying this to a function with more parameters returns those parameters as expected.

/* Returns 
[ 
  intial    = function, 
  condition = function, 
  next      = function, 
  selector  = nullable function 
]  
*/
Type.FunctionParameters ( Value.Type ( List.Generate ) )

To make this even more explicit, you can also visualise the above expression as follows. Let’s say you have a function type that says: ( myText as text, myValue as number ) as any.

// Output: [ myText = type text, myValue = type number ]
Type.FunctionParameters( type function ( myText as text, myValue as number ) as any )

Other functions related to Type.FunctionParameters are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/type-functionparameters