Uri.BuildQueryString
URIBuilds a URL query string from a record of key-value pairs.
Syntax
Uri.BuildQueryString(query as record) as textParameters
| Name | Type | Required | Description |
|---|---|---|---|
query | record | Yes | A record whose field names and values become query string parameters. |
Return Value
text — A URL-encoded query string.
Remarks
Uri.BuildQueryString converts a record into a URL-encoded query string (without the leading ?). Each field name becomes a parameter key, and each field value becomes the parameter value. Special characters in both keys and values are automatically percent-encoded.
This is useful when constructing URLs programmatically, especially in combination with Web.Contents:
``powerquery
let
BaseUrl = "https://api.example.com/search",
Params = [q = "power query", page = "1", limit = "50"],
FullUrl = BaseUrl & "?" & Uri.BuildQueryString(Params)
in
FullUrl
// Result: "https://api.example.com/search?q=power+query&page=1&limit=50"
``
Examples
Example 1: Build a query string from parameters
let
Params = [category = "Electronics", sort = "price", order = "asc"],
QueryString = Uri.BuildQueryString(Params)
in
#table({"QueryString"}, {{QueryString}})Result
QueryString | |
|---|---|
| 1 | category=Electronics&sort=price&order=asc |
Example 2: Handle special characters
let
Params = [search = "hello world", tag = "A&B"],
QueryString = Uri.BuildQueryString(Params)
in
#table({"QueryString"}, {{QueryString}})Result
QueryString | |
|---|---|
| 1 | search=hello+world&tag=A%26B |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks