Power BI自定义连接器导航表函数报错及UI定制问题咨询
问题1:无参数函数调用报错原因及解决
报错“未指定参数值”的核心原因是导航表中的无参数函数未绑定正确的类型元数据,Power BI无法识别它是无参数函数,因此默认弹出参数输入框。
你的代码中,AnotherFunction.Contents是无参数函数,但在导航表的Data列直接传入了函数本身,没有像TestFunction那样通过Value.ReplaceType绑定明确的函数类型。Power BI需要通过类型元数据判断函数的参数数量和类型。
解决步骤:
- 为无参数函数定义明确的类型(可同时添加文档元数据):
AnotherFunctionType = type function () as text meta [ Documentation.Name = "Another Function", Documentation.LongDescription = "Returns a static string when invoked." ];
- 在导航表的
Data列,用Value.ReplaceType绑定该类型:
{ "Another Function", "func2", Value.ReplaceType(AnotherFunction.Contents, AnotherFunctionType), "Function", "Function", true }
问题2:函数文档未生效的原因及解决
函数文档并非仅适用于顶级函数,导航表中的函数也能生效,你的问题是未给所有函数绑定带文档元数据的类型。
TestFunction虽然绑定了类型,但需要确保类型定义的元数据正确;而AnotherFunction之前没有绑定任何类型,自然无法显示文档。只要给导航表中的函数都绑定包含Documentation元数据的类型,就能触发自定义UI和文档展示。
修改后的完整代码
// This file contains your Data Connector logic [Version = "1.0.0"] section TestConnector; TestConnector = [ Authentication = [ Anonymous = [] ] ]; TestConnector.Publish = [ Beta = true, Category = "Other", ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") }, LearnMoreUrl = "https://powerbi.microsoft.com/", SourceImage = TestConnector.Icons, SourceTypeImage = TestConnector.Icons ]; TestConnector.Icons = [ Icon16 = { Extension.Contents("TestConnector16.png"), Extension.Contents("TestConnector20.png"), Extension.Contents("TestConnector24.png"), Extension.Contents("TestConnector32.png") }, Icon32 = { Extension.Contents("TestConnector32.png"), Extension.Contents("TestConnector40.png"), Extension.Contents("TestConnector48.png"), Extension.Contents("TestConnector64.png") } ]; [DataSource.Kind="TestConnector", Publish="TestConnector.Publish"] shared TestConnector.Contents = () => GetNavigationTable(); GetNavigationTable = () as table => let _table = #table( { "Name", "Key", "Data", "ItemKind", "ItemName", "IsLeaf" }, { { "Test Function", "func1", Value.ReplaceType(TestFunction, TestFunctionType), "Function", "Function", true }, { "Another Function", "func2", Value.ReplaceType(AnotherFunction.Contents, AnotherFunctionType), "Function", "Function", true } } ) in NavigationTable.FromTable(_table, {"Key"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf"); TestFunction = (message as text) as table => let result = #table( { "Column1", "Column2" }, {{ "Test Function A", message }} ) in result; TestFunctionType = type function ( message as (type text meta [ Documentation.FieldCaption = "Message", Documentation.FieldDescription = "Parameter description..." ]) ) as table meta [ Documentation.Name = "Test Function", Documentation.LongDescription = "Function description..." ]; AnotherFunction.Contents = () => "Returns a static string when invoked."; AnotherFunctionType = type function () as text meta [ Documentation.Name = "Another Function", Documentation.LongDescription = "Returns a static string when invoked." ]; NavigationTable.FromTable = (_table as table, keyColumns as list, nameColumn as text, dataColumn as text, itemKindColumn as text, itemNameColumn as text, isLeafColumn as text) as table => let tableType = Value.Type(_table), newTableType = Type.AddTableKey(tableType, keyColumns, true) meta [ NavigationTable.NameColumn = nameColumn, NavigationTable.DataColumn = dataColumn, NavigationTable.ItemKindColumn = itemKindColumn, NavigationTable.ItemNameColumn = itemNameColumn, NavigationTable.IsLeafColumn = isLeafColumn ], navigationTable = Value.ReplaceType(_table, newTableType) in navigationTable;
注:修正了NavigationTable.FromTable中的元数据配置,将原Preview.DelayColumn改为标准的NavigationTable.ItemNameColumn,避免潜在的预览异常。
内容的提问来源于stack exchange,提问作者Petr Broz
相关产品推荐
相关产品推荐

