Finding the Nearest Anything in Alteryx

by Tanya Fischer

There are several example where one might be interested in finding the nearest option available. As a company you might be interested whether your warehouses are in a reasonable distance from the stores where the products are being sold or as a city planner or maybe even as a politician you might want to know which hospital is the closest to reach for the population.

Let’s stick with the hospital example. Let’s say we have a list of cities and a list of hospitals, both containing the latitude and longitude of the listed locations.

First of all we’re going to create points from the latitudes and longitudes by using the “Create Points” tool. If your columns are already named something like “lat” and “lon” Alteryx will automatically detect them correctly. You have now created centroids for each location. It’s a good idea to rename your centroids so that you know later what they are referring to. This will prevent confusion when combining the data.

You could then simply connect your two lists to the “Find Nearest” tool. The tool is asking for a “Target” input and an optional “Universe” input. In our case the cities are the Target and the Universe are the hospitals. The tool lets you also decide how many nearest points you want to find and what the maximum distance in miles or kilometers should be. If you have a special dataset you could also apply the maximum drivetime and take traffic into account.

You’ll receive two outputs from that – matched and unmatched data. The matched data will include all the cities that are within the set radius around the hospitals and the unmatched cities are further than the maximum distance away from a hospital. Additionally, the browse tool will show you your target (red) and universe (green) locations on a map.

This is probably the easiest way to find the nearest anything in Alteryx. The downside is that you can’t see the radius around the universe location which might be useful when looking at overlapping service areas.

To achieve this you can work with trade areas. Using the “trade area” tool in Alteryx you can create a radius, a doughnut or even a drivetime radius around the universe centroid. You then combine those with the target centroids via the “Spatial Match” tool where you can configure exactly what cases you want to display. Here we want to look at the locations “Where Target Within Universe”. You will once again receive matched and unmatched data and can view the locations on a map, only this time you will be able to see the trade areas of the universe locations and this way can spot possible overlaps.