SOLVED

Referencing A Text String (URL) In A Power Query

Copper Contributor

I am using Excel and Quick Base.  Quick Base allows querying data via URL. I have successfully set up and run a query in Excel Power Query from our Quick Base database.

 

Here is an example of what that Power Query looks like:

 

let
Source = Csv.Document(Web.Contents("https://hardermech.quickbase.com/db/jkii2h8?act=API_GenResultsTable&usertoken=usertoken&options=csv&...}"
),[Delimiter=","]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])
in
#"Promoted Headers"

 

Instead of hard coding the entire text string for the URL, I want to build up the text string (parameterize it) in an Excel cell so that I can reference various values in the spreadsheet, then pull that string into the query source statement above.

I have found some online resources for building a Power Query to reference a specific cell on a spreadsheet.

How do I then reference that parameter correctly in this Source statement?

5 Replies
best response confirmed by JonInPDX (Copper Contributor)
Solution

@JonInPDX 

If that's one cell parameter, you may name such cell

image.png

query it and use as parameter

let
    GetURL = Excel.CurrentWorkbook(){[Name="URLstring"]}[Content][Column1]{0},
    Source = Csv.Document(Web.Contents(GetURL),[Delimiter=","]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])
in
    #"Promoted Headers"

 

If there are few parameters, idea is the same but you organize you parameter into Excel table, query it, combine value into one string and use to access web resource.

@Sergei Baklan Fantastic! That worked perfectly. Thank you!

@JonInPDX , you are welcome

Is there a way to make this query work for a different reference on each sheet? The named range seems to be at a workbook level. I want to have different URLs in multiple sheets. (At the moment if I copy a sheet containing a named range and tables and then change the value in the named range, it still looks up the named range in the first sheet as that is at the workbook level. Is there a way of referencing a cells value in the active sheet? Instead of using a named range?

@BenBennett27 

Power Query doesn't know which worksheet is active. You may define names on sheets level and when use same name combines with sheet name

image.png

 

1 best response

Accepted Solutions
best response confirmed by JonInPDX (Copper Contributor)
Solution

@JonInPDX 

If that's one cell parameter, you may name such cell

image.png

query it and use as parameter

let
    GetURL = Excel.CurrentWorkbook(){[Name="URLstring"]}[Content][Column1]{0},
    Source = Csv.Document(Web.Contents(GetURL),[Delimiter=","]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])
in
    #"Promoted Headers"

 

If there are few parameters, idea is the same but you organize you parameter into Excel table, query it, combine value into one string and use to access web resource.

View solution in original post