If you have zip code data for your subscribers and store locations in your Marketing Cloud account, you can use a SQL Query to determine distances between them. With this method you can determine which store is closest to each of your subscribers.
There are a few bits and pieces about geolocation or geo-targeting in the official SFMC documentation, but I think it’s much more helpful to see an example start to finish.
Here are the pieces:
- A subscriber data extension that includes a zip code column
- A store data extension that includes a zip code column
- A zip code data extension that includes X, Y, and Z-axis columns
- A query that writes to a new data extension
Zip_Axisdata above has been limited to those zip codes in the example.
I’ve seen people simply store the latitude and longitude for each zip and then calculate the X, Y, and Z values on the fly in the SQL query. However, I prefer calculating those columns beforehand. The queries will be faster and easier to read. You can do that with a query like this:
This query pulls it all together. The round function and case statements do the dirty work of the calculations between the two zip codes. The ranking and partition part picks out the closest store per subscriber.
For further reading
- Data Extensions
- Query Activities
- Import Activities
- Microsoft Transact-SQL (T-SQL) Reference
- Distances between Zips (for verification)
- Calculating x, y, z axis values in SQL
- 2018-09-16 – Reviewed and updated the sample data, tweaked a table names on the query and re-tested it.