Uri.Combine

D

T

The M Code Behind the Power Query M function Uri.Combine

In this article, we will explore the M code behind the Uri.Combine function, how it works, and some examples of how it can be used in Power Query.

What is the Uri.Combine function?

The Uri.Combine function is a Power Query M function that allows users to combine two or more URIs into a single URI. URIs are used to identify resources on the internet, such as web pages, images, or videos.

The Uri.Combine function takes two or more URIs as arguments and combines them into a single URI. It is similar to the CONCATENATE function in Excel, but for URIs.

How does the Uri.Combine function work?

The Uri.Combine function works by taking two or more URIs as arguments and concatenating them into a single URI. The function also handles any necessary formatting, such as adding a forward slash (/) between URIs if needed.

For example, if we have two URIs, “https://www.example.com” and “/products”, we can use the Uri.Combine function to combine them into a single URI:


Uri.Combine("https://www.example.com", "/products")


This will return the following URI:


"https://www.example.com/products"


Examples of using the Uri.Combine function

The Uri.Combine function can be used in a variety of ways in Power Query. Here are some examples of how it can be used:

Combining a base URL with a relative URL

In some cases, we may have a base URL and a relative URL that we want to combine into a single URI. For example, we may have a list of products with URLs like “/products/1”, “/products/2”, etc., and we want to combine them with a base URL like “https://www.example.com”.

We can use the Uri.Combine function to combine the base URL with the relative URLs:


let

baseUrl = "https://www.example.com",

products = {"1", "2", "3"},

urls = List.Transform(products, each Uri.Combine(baseUrl, "/products/" & _))

in

urls


This will return a list of URLs like:


{

"https://www.example.com/products/1",

"https://www.example.com/products/2",

"https://www.example.com/products/3"

}


Combining multiple URIs

We can also use the Uri.Combine function to combine more than two URIs. For example, we may have a base URL, a category URL, and a product URL that we want to combine into a single URI.


let

baseUrl = "https://www.example.com",

category = "electronics",

product = "12345",

url = Uri.Combine(baseUrl, "/category/" & category, "/product/" & product)

in

url


This will return the following URI:


"https://www.example.com/category/electronics/product/12345"


The Uri.Combine function is a powerful tool in Power Query that allows users to combine two or more URIs into a single URI. By understanding the M code behind the function and how it works, we can use it to transform and analyze data from a variety of sources with ease.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)