Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
yamaga
Frequent Visitor

Custom Connectors - AllowedValues dropdown dynamic values

Hi,

I am working on a custom connector for Power Bi to get Data from multiple APIs.

 

The user could select the API instance then the list of all available tables in this API should be shown in a list field. Then write the desired query in the Query field.

 

yamaga_0-1646921254459.png

 

Actually I could show the of the list of tables when I hardcoded them in my code.

I want to dynalically show the tables depending on the selected API.

for example:

API 1 => table1, table2

API 2 => table3, table4, table5...

 

I use a function to get this list.

 

My question is how to render the list of table so it shows the table dynamically without hardcode it!

 

The hardcoded list of tables:

yamaga_2-1646921902642.png

 

 

 

 

 

MyQueryType = type function (

APIType as (type text meta [
        Documentation.FieldCaption = "API name",
        Documentation.FieldDescription = "Enter the API name",
        Documentation.AllowedValues = { "BS_PARAMETER", "Elastic API DSL", "Elastic API SQL" }
        //Documentation.AllowedValues = Indices2
                        
        ]),
PartnerCodeType as (type text meta [
        Documentation.FieldCaption = "Partner code",
        Documentation.FieldDescription = "Enter the partner code",
        Documentation.AllowedValues = { "jp_demo", "bilan_sanguin" }
        ]),
TableType as (type text meta [
        Documentation.FieldCaption = "Table",
        Documentation.FieldDescription = "Enter you query",
        Documentation.AllowedValues = { "table1", "table2", "table3", "table4", "table5" }
        ]),
QueryType as (type text meta [
        Documentation.FieldCaption = "Query",
        Documentation.FieldDescription = "Enter you query",
        Documentation.SampleValues = { "{    ""query"": {        ""match_all"":{}    }}" },
        Formatting.IsMultiLine = true
        ])


    )
    as table meta [
        Documentation.Name = "My Custom Query",
        Documentation.LongDescription = "Long Desc"
        ];

 

 

 

 

 

I created a function Indices() that gets the list of table for each API then I call it in the MyQueryType function:

 

 

 

 

 

 

 

 

 

MyQueryType = type function (

APIType as (type text meta [
        Documentation.FieldCaption = "API name",
        Documentation.FieldDescription = "Enter the API name",
        Documentation.AllowedValues = { "BS_PARAMETER", "Elastic API DSL", "Elastic API SQL" }
        //Documentation.AllowedValues = Indices2
                        
        ]),
PartnerCodeType as (type text meta [
        Documentation.FieldCaption = "Partner code",
        Documentation.FieldDescription = "Enter the partner code",
        Documentation.AllowedValues = { "jp_demo", "bilan_sanguin" }
        ]),
TableType as (type text meta [
        Documentation.FieldCaption = "Table",
        Documentation.FieldDescription = "dec",
        Documentation.AllowedValues = Indices()
        ]),
QueryType as (type text meta [
        Documentation.FieldCaption = "Query",
        Documentation.FieldDescription = "Enter you query",
        Documentation.SampleValues = { "{    ""query"": {        ""match_all"":{}    }}" },
        Formatting.IsMultiLine = true
        ])


    )
    as table meta [
        Documentation.Name = "My Custom Query",
        Documentation.LongDescription = "Long Desc"
        ];

//Other code snippet

//Get ES Metadata: indexes
Indices = 
        let
            api_url = "http://MyURL:9200/_cat/indices?format=json",
            response = Web.Contents(api_url),
            source = Json.Document(response),
            #"Converted to Table" = Table.FromList(source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
            #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"index"}, {"Column1.index"}),
            #"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{{"Column1.index", type text}}),
            mylist = Table.ToList(#"Expanded Column1")
            //mylistb = Table.TransformColumnTypes(mylist,{{"Column1.index", type text}})
            //totext = Text.Combine(mylist, ",")
    in
            //#"Changed Type";
            mylist;

 

 

 

 

 

This question is already asked but no solution is given until today!

https://community.powerbi.com/t5/Desktop/Custom-Data-Connector-UI-Dropdown-list/td-p/484102

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @yamaga ,

 

There doesn't seem to be a way yet for what you're trying to achieve.

 

In addition, you can find how to create dynamic function parameters in Power BI from these links:

Creating Dynamic Parameters in Power Query

Dynamic API parameters in Power BI

Custom Functions Made Easy in Power BI Desktop

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-stephen-msft 

Thanks for this answer.

 

Actually, I want to do all the logic in the Custom Connector code with Power Query SDK.

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors