Hi!
I'm able to use a web service that retrieves data from an external source using the Excel/Power Query ODATA feed panel but is it possible to pass Excel row/col reference locations to the URL?
Take for example, I have a customer file and I want to validate if the post codes are valid using a web service. The post code will of course change for each customer record, so is it possible to pass the post code value to the ODATA url?
Thanks for any advice 😀
Martin
Short answer: Not directly. You can’t simply reference “cell A2” or “the current row’s postal code” in the OData feed URL box. However, you can achieve row-by-row lookups by creating a custom function in Power Query that calls your external service, and then invoking that function on each row. The trick is that it isn’t done in the basic OData feed panel, but rather through Power Query M code and custom columns.
Below is an outline of how you could approach it.
Create a Custom Function:
In Power Query, go to Home > Advanced Editor and write (or paste) a function that calls your web service, using a parameter (e.g., PostalCode) in the URL.
For example, something like:
// This is a simplistic function example
// that calls "https://myservice.com/validate?postalCode=XXXXX"
// and returns some validation result.
// Rename "fnValidatePostalCode" to whatever you want
// and adjust the URL to match your web service.
let
fnValidatePostalCode = (pc as text) as nullable text =>
let
Source = Web.Contents(
"https://myservice.com/validate?postalCode=" & pc
),
// ... apply JSON or text transforms here, if needed
Result = Text.FromBinary(Source)
in
Result
in
fnValidatePostalCode
Once you’ve defined this function, you’ll see a new query in Power Query named something like fnValidatePostalCode.
Invoke the Function on Each Row:
Suppose you already have a query called CustomerData with a column named PostalCode.
In Power Query, select the CustomerData query.
Go to Add Column > Invoke Custom Function.
In the dialog that appears, choose:
New column name: something like PostalCodeValidation.
Function Query: pick the function you just created (e.g., fnValidatePostalCode).
PostalCode: choose the PostalCode column from your CustomerData query.
Click OK. Power Query will create a new column that calls the custom function once for each row, passing in that row’s postal code.
If You Must Filter via OData Parameters
Some OData feeds allow queries like:
https://myODataService/Customers?$filter=PostalCode eq '12345'
But typically you’d still do this one at a time in a custom function. You can’t just open “Get Data -> OData Feed” once and pass each row’s postal code automatically.
You would:
Create a function fnGetCustomerByPostalCode(postalCode as text) that returns OData.Feed("...?$filter=PostalCode eq '" & postalCode & "'").
Invoke that function for each row in your table, similarly to the steps above.
Many thanks for the detailed information - It’s much appreciated- I’ll definitely give it a go 😀