# Distance betweeen classified Points

I got two sets of points.

1. The first set has a unique `ID`
2. The second set references to this `ID` (one-to-many).

So I merged the two sets. Now every point in the joined table has the `X` and `Y` coordinates from the related first set.

``````Name;ID;X;Y;X_2;Y_2;Distance
``````

Every `X` and `Y` is unique but `X_2` and `Y_2` repeats from a given set.

Now I would like to calculate the distance between `(X,Y)` and `(X_2,Y_2)` in the new column for each row.

I tried `distance()` but I'm way too new in Python to get it working.

I also tried some tools like Distance Matrix, but I got results for all distances (or to the number defined) but not only to the distances in one row. Or between Points sharing the same `ID`.

Executed in QGIS 2.18 and QGIS 3.0.3

In the `Field Calculator/Expression dialog`, please try

``````distance(make_point("X", "Y"), make_point("X_2", "Y_2"))
``````

Function `distance()` returns the minimum distance (based on spatial ref) between two geometries in projected units.

Syntax: distance(`geometry a`, `geometry b`)

``````distance(geom_from_wkt('POINT(' + "X1" || ' ' || "Y1" + ')'), geom_from_wkt('POINT(' + "X2" || ' ' || "Y2" +')')) 