PQ Custom Function dropdown

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
3,957
Office Version
  1. 365
Platform
  1. Windows
I have a simple PQ query here.

Power Query:
(tbl as text) as table =>
let   
    Source = Excel.CurrentWorkbook(){[Name=tbl]}[Content],
    List = Table.AddColumn(Source, "Explode", each {1..[APP]}),
    Explode = Table.ExpandListColumn(List, "Explode"),
    RC = Table.RemoveColumns(Explode,{"Explode"}),
    ToOne = Table.TransformColumns(RC,{{"APP", each 1}})
in
    ToOne

When I invoke the custom function I need to manually type in the Table name. How would I make it to where it gives a dropdown of all the available tables in the workbook?

I have a list of all the tables in the workbook already, just need to know how to let the user choose from that list.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Upvote 0
Thanks Sandy,

One of those links looks similar, but I'm not sure if it's exactly what I'm looking for. I'll have to dig into it a bit more.

I did get it to work, but it seems hacky and getting it to look like a legit PQ function is still a bit beyond me at this point. I'd also like to add another parameter that is dependent on the first parameter, i.e. get a list of columns based on the table selected in the first parameter. But we'll see.

Here's the working code so far. Thanks again for the links.

Power Query:
let
    fn = (tbl as text) as table =>
        let
            Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
            List = Table.AddColumn(Source, "Explode", each {1..[APP]}),
            Explode = Table.ExpandListColumn(List, "Explode"),
            RC = Table.RemoveColumns(Explode,{"Explode"}),
            ToOne = Table.TransformColumns(RC,{{"APP", each 1}})
        in
            ToOne,

    fnType = type function
        (
            Table_Name as (type text meta [Documentation.AllowedValues = tableList])
        ) as list
    in
    Value.ReplaceType(fn,fnType)
 
Upvote 0

Forum statistics

Threads
1,223,760
Messages
6,174,341
Members
452,555
Latest member
colc007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top