Power Query Custom Function Template

m power query template

Documentation of the ETL code is crucial for subsequent reusability and the ability to know your procedure.

Power Query Custom Function Template

In my article Documentation options in Power Query, which I published some time ago, I showed a small template for creating Custom Functions in Power Query. This template is still up-to-date and more essential than ever! Why? Because with the arrival of Fabric, it is perfectly usable for Dataflow Gen 2.

// --------------------------- Function ------------------------------
let
    // --------------------------- Fucntion segment -----------------------------------
    output =
        (/*parameter as text, optional opt_parameter as text*/) /*as text*/ =>      // Input definition + Function output type definition
            let                                                                         // Inner function steps declaration
                initStep = "",
                lastStep = ""
            in
                lastStep,                                                               // Output from inner steps
    // --------------------------- Documentation segment ------------------------------
    documentation = [
        Documentation.Name = " NAME OF FUNCTION ",                                      // Name of the function
        Documentation.Description = " DESCRIPTION ",                                    // Decription of the function
        Documentation.Source = " URL / SOURCE DESCRIPTION ",                            // Source of the function
        Documentation.Version = " VERSION ",                                            // Version of the function
        Documentation.Author = " AUTHOR ",                                              // Author of the function
        Documentation.Examples =                                                        // Examples of the functions
        {
            [
                Description = " EXAMPLE DESCRIPTION ",                                  // Description of the example
                Code = " EXAMPLE CODE ",                                                // Code of the example
                Result = " EXAMPLE RESULT "                                             // Result of the example
            ]
        }
    ]
    // --------------------------- Output --------------------------------------------
in
    Value.ReplaceType(                                                                  // Replace type of the value
        output,                                                                         // Function caller
        Value.ReplaceMetadata(                                                          // Replace metadata of the function
            Value.Type(output),                                                         // Return output type of function
            documentation                                                               // Documentation assigment
        )
    )
// ------------------------------------------------------------------------------------
Power Query Custom Function Template
Older post

Date Dimension

Documentation of the ETL code is crucial for subsequent reusability and the ability to know your procedure.

Newer post

Composite Card

Documentation of the ETL code is crucial for subsequent reusability and the ability to know your procedure.

Power Query Custom Function Template