Decode URI in Power Query with custom Uri.UnescapeDataString function

When working with cloud data sources you might encounter links where spaces show up as “%20” instead for example. This is called URI escaping or encoding. In Power Query there is a native function that does this kind of encoding: Uri.EscapeDataString – PowerQuery M | Microsoft Learn
However, a native function that does just the opposite is missing. Fortunately, this can be achieved with a custom function that I have found in the Power BI forum:

Uri.UnescapeDataString


let func =
(data as text) as text =>
let
DecodedText = Uri.Parts("http://contoso?a=" & data)[Query][a]
in
DecodedText ,
documentation = [
Documentation.Name = " Uri.UnescapeDataString ",
Documentation.Description = " Decodes special characters in the input data according to the rules of RFC 3986. ",
Documentation.LongDescription = " Decodes special characters in the input data according to the rules of RFC 3986. ",
Documentation.Category = " UriFunctions ",
Documentation.Source = " www.TheBIcountant.com . ",
Documentation.Version = " 1.0 ",
Documentation.Author = " Source: https://community.fabric.microsoft.com/t5/Desktop/How-to-convert-these-encode-url-to-normal-text/td-p/2388189 ",
Documentation.Examples = {[Description = " ",
Code = " Uri_UnescapeDataString(""Hello%20World"") ",
Result = " ""Hello World""
"]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))

I hope it helps you as it did me.

Enjoy and stay queryious 😉

Comments (5) Write a comment

  1. Pingback: Decoding URIs in Power Query – Curated SQL

  2. K11 Games is known for its simple interface and easy account access. Players can register quickly, log in securely, and enjoy different gaming features from their mobile devices.

    Reply

  3. 66 Game Download helps users find information about downloading the latest app version, installing the APK, updating the app, creating an account, and logging in safely.

    Reply

Leave a Reply