Uri.BuildQueryString

URI

Builds a URL query string from a record of key-value pairs.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Uri.BuildQueryString(query as record) as text

Parameters

NameTypeRequiredDescription
queryrecordYesA record whose field names and values become query string parameters.

Return Value

textA 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:

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}})
Applied Steps

The final output — a single-row table displaying the assembled query string.

QueryString
1category=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}})
Applied Steps

The final output — a single-row table displaying the percent-encoded query string.

QueryString
1search=hello+world&tag=A%26B

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks
Contributors
kyleamueller