Forum Discussion
Functions in Navigation Tables for Power BI Custom Connector
- Anonymous1 year ago
Hi petrbroz ,
Yes, this is the expected behavior when a function in a custom connector does not require any parameters. When you click the function in the navigation pane, Power BI will display a message indicating that no parameter values are specified because the function does not need any input from the user. This is a standard message to show that there are no parameters to pass for the function when you invoke it.
Best Regards
Thank you Anonymous. After some more research I've found that Power BI shows a slightly different message depending on whether the function accepts any parameters:
- If the function accepts no parameters, Power BI shows "No parameter values specified"
- If the function accepts parameters (doesn't matter whether it's documented or not), Power BI shows "Parameter value not specified"
I think the naming is a bit misleading. Also, it would be nice if the behavior was:
- If the function accepts no parameters, Power BI shows the results of calling the function
- If the function accepts parameters, Power BI shows UI to input these parameters (just like it does for the top level function), and then shows the results based on the provided inputs
.
Source code:
[Version = "1.0.0"]
section TestConnector;
TestConnector = [
Authentication = [
Anonymous = []
]
];
TestConnector.Publish = [
Beta = true,
Category = "Other",
ButtonText = {"Test Connector", "Test Connector"},
LearnMoreUrl = "https://powerbi.microsoft.com/"
];
[DataSource.Kind="TestConnector", Publish="TestConnector.Publish"]
shared TestConnector.Contents = () =>
let
records = {
[
Name = "Function with no params",
Key = "f1",
Data = FunctionWithNoParams,
ItemKind = "Function",
ItemName = "Function",
IsLeaf = true
],
[
Name = "Function with params (undocumented)",
Key = "f2",
Data = FunctionWithParams,
ItemKind = "Function",
ItemName = "Function",
IsLeaf = true
],
[
Name = "Function with params (documented)",
Key = "f3",
Data = Value.ReplaceType(FunctionWithParams, FunctionWithParamsType),
ItemKind = "Function",
ItemName = "Function",
IsLeaf = true
]
}
in
NavigationTable(records);
FunctionWithNoParams = () as table =>
#table(
{"Column"},
{{"Foo"}}
);
FunctionWithParams = (name as text) as table =>
#table(
{"Name"},
{{name}}
);
FunctionWithParamsType = type function (
name as (type text meta [
Documentation.FieldCaption = "My Param Name",
Documentation.FieldDescription = "Parameter description..."
])
) as table meta [
Documentation.Name = "My Function Name",
Documentation.LongDescription = "Function description..."
];
NavigationTable = (records as list) as table =>
let
_table = Table.FromRecords(records),
tableType = Value.Type(_table),
newTableType = Type.AddTableKey(tableType, {"Key"}, true) meta
[
NavigationTable.NameColumn = "Name",
NavigationTable.DataColumn = "Data",
NavigationTable.ItemKindColumn = "ItemKind",
Preview.DelayColumn = "ItemName",
NavigationTable.IsLeafColumn = "IsLeaf"
]
in
Value.ReplaceType(_table, newTableType);
Since you say this is the expected behavior, I'll accept your solution, and I'll submit my suggestions in https://ideas.fabric.microsoft.com. Thank you!
petrbroz wrote:I think the naming is a bit misleading. Also, it would be nice if the behavior was:
- If the function accepts no parameters, Power BI shows the results of calling the function
- If the function accepts parameters, Power BI shows UI to input these parameters (just like it does for the top level function), and then shows the results based on the provided inputs
That is entirely possible, as many screenshots of different connectors show you. What the documentation did not tell you is that the line
Preview.DelayColumn = itemNameColumnin the ToNavigationTable helper just does not work with functions! You need to remove it to have the function parameters shown.
When you have functions and other types, like tables, then you would need 2 different ToNavigationTable functions. One with, and one without that line.
Crossreference