Power Query – Uri.Combine Examples

I frequently refer to this table of Uri.Combine combinations, so thought it might be worthwhile to post.

BasePathUri.Combine
https://www.microsoft.comrelative/pathhttps://www.microsoft.com/relative/path
https://www.microsoft.com/absolute/pathhttps://www.microsoft.com/absolute/path
https://www.www.microsoft.com/relative/pathhttps://www.www.microsoft.com/relative/path
https://www.www.microsoft.com//absolute/pathhttps://www.www.microsoft.com/absolute/path
https://www.microsoft.com/originalPathrelative/pathhttps://www.microsoft.com/relative/path
https://www.microsoft.com/originalPath/absolute/pathhttps://www.microsoft.com/absolute/path
https://www.microsoft.com/originalPath/relative/pathhttps://www.microsoft.com/originalPath/relative/path
https://www.microsoft.com/originalPath//absolute/pathhttps://www.microsoft.com/absolute/path
https://www.microsoft.com/originalPath/plusrelative/pathhttps://www.microsoft.com/originalPath/relative/path
https://www.microsoft.com/originalPath/plus/absolute/pathhttps://www.microsoft.com/absolute/path
https://www.microsoft.com/originalPath/plus/relative/pathhttps://www.microsoft.com/originalPath/plus/relative/path
https://www.microsoft.com/originalPath/plus//absolute/pathhttps://www.microsoft.com/absolute/path

The M code used to generate this:

let
    sourceUrls = {
        "https://www.microsoft.com",
        "https://www.www.microsoft.com/",
        "https://www.microsoft.com/originalPath",
        "https://www.microsoft.com/originalPath/",
        "https://www.microsoft.com/originalPath/plus",
        "https://www.microsoft.com/originalPath/plus/"
    },
    paths = { "relative/path", "/absolute/path" },
    urlsToTable = Table.FromList(sourceUrls, Splitter.SplitByNothing()),
    addPaths = Table.AddColumn(urlsToTable, "relatives", each paths),
    expandPaths = Table.ExpandListColumn(addPaths, "relatives"),
    rename = Table.RenameColumns(expandPaths,{{"Column1", "Base"}, {"relatives", "Path"}}),
    uriCombine = Table.AddColumn(rename, "Uri.Combine", each Uri.Combine([Base], [Path]), type text)
in
    uriCombine

Leave a Reply

Your email address will not be published. Required fields are marked *