Can the list of Tables presented by a Function be filtered?

jdellasala

Well-known Member
Joined
Dec 11, 2020
Messages
755
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I have a PQ Function that starts like this:
Power Query:
(FredURL as table) =>
let
    SrcURL = FredURL{0}[Column1],
The function works great, but when invoked, a list of ALL tables in the Workbook is presented. Is there a way to filter that list so that only table names that start with "url" are presented?

This relates to my post here which I've already posted one update for.

Your help is appreciated, as is your feedback on the article.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Can't you filter the list of tables before invoking the function?
 
Upvote 0
So I figured out how to get a table of the queries I want and the values associated with them:
Power Query:
let
    Source = #shared,
    ConvertedToTable = Record.ToTable(Source),
    FilteredRowsStartWithurl = Table.SelectRows(ConvertedToTable, each Text.StartsWith([Name], "url")),
    FilteredOutURLFred = Table.SelectRows(FilteredRowsStartWithurl, each ([Name] <> "urlFRED")),
    ExpandedValue = Table.ExpandTableColumn(FilteredOutURLFred, "Value", {"Column1"}, {"URL"})
in
    ExpandedValue
That results in this table:
NameURL
urlRealGDPhttps://api.stlouisfed.org/fred/series/observations?series_id=A191RL1Q225SBEA&frequency=q&observation_start=1959-01-01&observation_end=2023-01-01&api_key=3b1c0dca84ae9431560c2ac624a16aee
urlUNRATEhttps://api.stlouisfed.org/fred/series/observations?series_id=UNRATE&frequency=q&observation_start=1959-01-01&observation_end=2023-01-01&api_key=3b1c0dca84ae9431560c2ac624a16aee
urlPCEPIhttps://api.stlouisfed.org/fred/series/observations?series_id=PCEPI&frequency=q&observation_start=1959-01-01&observation_end=2023-01-01&api_key=3b1c0dca84ae9431560c2ac624a16aee
urlPCEPILFEhttps://api.stlouisfed.org/fred/series/observations?series_id=PCEPILFE&frequency=q&observation_start=1959-01-01&observation_end=2023-01-01&api_key=3b1c0dca84ae9431560c2ac624a16aee
urlDFFhttps://api.stlouisfed.org/fred/series/observations?series_id=DFF&frequency=q&observation_start=1959-01-01&observation_end=2023-01-01&api_key=3b1c0dca84ae9431560c2ac624a16aee

I'd like to use the Name column to provide a list for a function which would then use the URL of the Name selected. I've tried several ways, but none are working.
As I said earlier, the function now uses the parameter
Power Query:
(FredURL as table) =>
When the function is invoked all of the queries that produce a Table are listed. I only want the names of the list above to be presented. I want the function to present only the Name from the query above.
 
Upvote 0
It seems to me you shouldn't be invoking the function directly since it expects you to pass a table as a parameter. You should be calling the function from another query and passing whatever table you need (e.g. the ExpandedValue table above).
 
Upvote 0
It seems to me you shouldn't be invoking the function directly since it expects you to pass a table as a parameter. You should be calling the function from another query and passing whatever table you need (e.g. the ExpandedValue table above).
Thanks Roy. That's kind of my ask. I don't see how to do that. I looked at using a parameter, but a parameter has no access to a Table object. I might be able to do a text string since that's really what I'm after with the function which uses {0}[Column1] of the table, but I don't see a way to provide that automatically.
Can you provide an example?
 
Upvote 0
You haven't really explained how you plan to use it. You could alter the function so that it takes a text argument, then simply call it from an additional column in the query in post 4. You'd then have a table returned for each URL.
 
Upvote 0
I created a template that creates a URL to fetch data using an API which I posted here and updated here.
The intent is that columns B and C in the update are copied to a new sheet, and then the cell with the constructed URL is given a Name that starts with "url", it is brought into Power Query. Rather than save the URL as a string, it's saved as a table, and then the function's parameter requests a table name, and since it's a standard single column, single row table uses urlTable{0}[Column1] to extract the URL and process its response.
I'm able to generate a table of URL Names and their associated URLs like this:
Power Query:
let
    Source = #shared,
    ConvertedToTable = Record.ToTable(Source),
    FilteredRows = Table.SelectRows(ConvertedToTable, each Text.StartsWith([Name], "url")),
    ExpandedValue = Table.ExpandTableColumn(FilteredRows, "Value", {"Column1"}, {"Column1"})
in
    ExpandedValue
That results in a table like this (with more rows):
but I haven't been able to find out how that can be used to use as the parameter of a PQ Function.
 
Upvote 0
I haven't been able to find out how that can be used to use as the parameter of a PQ Function.
You need another query that calls the function passing the relevant table as a parameter. (just like a parameterised function in VBA or any other language).
 
Upvote 0
You need another query that calls the function passing the relevant table as a parameter. (just like a parameterised function in VBA or any other language).
Assuming the table of URL Names and URLs is called URLTable, how would a function use that so that when the function was called from the Queries & Connections pane, that table, or preferably just the Names in that table, were presented to the user. As it stands now, all tables in the Workbook are presented.
 
Upvote 0

Forum statistics

Threads
1,223,944
Messages
6,175,554
Members
452,652
Latest member
eduedu

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