# Calculating distance between multiple associated points in QGIS

I have two large lists of points. List A contains the location of a farmers farmstead and list B contains locations of pastures. Both lists have a column that will identify the farmer that the pasture or farmstead belongs to. There is only one farmer per farmstead but there may be several pastures linked to each farmer. Each farmer does not have a pasture.

So to my question, how do I calculate the distance between each pasture and its farmers farmstead? I know how to calculate the distance between two given points but since these are rather large sets it is not possible to go through the lists point by point. Is there a way to set this up without making a matrix of all possible combinations of points? The lists contain ~65000 and ~2000 points which means that such a matrix would become quite cumbersome to handle.

I'm using QGIS 2.18 and my projection (EPSG:3006) uses meters as the map unit.

This thread How could you calculate the distance between multiple associated points, specifically a list of structures serving specific addresses within CartoDB? is similar but using a different software.

It's possible to do that from your XY coordinates. First you should create a table join between your list A to list B (this way because of 1 farmer per farmstead. it's a left join). Then create a new field with the field calculator. Use distance formula like euclidian of distance `√((xA-xB)²+(yA-yB)²`) or anyone else. this way you create your distance field in your projection.