Uri.EscapeDataString

URI

Percent-encodes special characters in a text value for safe use in a URI.

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

Syntax

Uri.EscapeDataString(data as text) as text

Parameters

NameTypeRequiredDescription
datatextYesThe text value to percent-encode.

Return Value

textThe percent-encoded text value.

Remarks

Uri.EscapeDataString applies percent-encoding to a text value, replacing characters that are not allowed in URI components (spaces, ampersands, slashes, etc.) with their %XX hex equivalents. For example, a space becomes %20, and & becomes %26.

This is useful when embedding dynamic values directly into URL path segments or query parameters where Uri.BuildQueryString is not appropriate (e.g., in path segments):

``powerquery let ItemName = "Widget A/B", Url = "https://api.example.com/items/" & Uri.EscapeDataString(ItemName) in Url // Result: "https://api.example.com/items/Widget%20A%2FB" ``

Note: Uri.BuildQueryString already encodes values automatically, so you do not need to call Uri.EscapeDataString on values passed to Uri.BuildQueryString.

Examples

Example 1: Encode special characters for a URL

let
    Values = {"Hello World", "A&B=C", "path/to/file", "100% done"},
    Encoded = List.Transform(Values, each Uri.EscapeDataString(_)),
    Rows = List.Transform({0..List.Count(Values)-1}, each {Values{_}, Encoded{_}})
in
    #table({"Original", "Encoded"}, Rows)
Result
Original
Encoded
1Hello WorldHello%20World
2A&B=CA%26B%3DC
3path/to/filepath%2Fto%2Ffile
4100% done100%25%20done

Compatibility

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