Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Pass name of function to a function - NOT as text

Greetings,  I am working on a PQ function to pull back the metadata for a chosen function (user generated, or #shared).  I am aware I can just as easily click in the box that says Function after r...
  • AntrikshSharma's avatar
    3 years ago

    Anonymous Try this:

    ( FunctionName as text ) =>                                                                                      
        let
            SharedLibrary = #shared,
            ToTable = Record.ToTable ( SharedLibrary ),
            GetFunction = Table.SelectRows ( ToTable, each [Name] = FunctionName )[Value]{0},
            Source = Value.Metadata ( Value.Type ( GetFunction ) ),                                                                                                                      
            ConvertToTable = Record.ToTable ( Source ),
            PivotName = 
                Table.Pivot (
                    ConvertToTable,
                    List.Distinct ( ConvertToTable[Name] ),
                    "Name",
                    "Value"
                ),
            ExpandExamplesToRecord = Table.ExpandListColumn ( PivotName, "Documentation.Examples" ),
            ExpandExamplesToText = 
                Table.ExpandRecordColumn (
                    ExpandExamplesToRecord,
                    "Documentation.Examples",
                    { "Description", "Code", "Result" },
                    {
                        "Documentation.Examples.Description",
                        "Documentation.Examples.Code",
                        "Documentation.Examples.Result"
                    }
                )
        in
            ExpandExamplesToText