You can use
Menu Processing / Toolbox / Join attributes by nearest. It will create a new layer
joined layer - a copy of
Y, but if you set
Maximum nearest neighbors to 2, you will get two duplicate features with the attributes from both points from
X. You also get an attribute for the distance. You can now copy the attributes from line 2 to line 1.
To add the attribute values of feature no. 2 to feature no. 1, use
Refactor fields (see documentation Refactor fields). Create new fields with the same name, but a prefix (like
2_) and this expression:
attribute (get_feature_by_id (@layer,2), '[attribute_name]'), where you have to replace
[attribute_name] with the name of the attribute to be copied (screenshot 2).
If you have a lot of attributes to copy, you can run
Refactor fields in batch mode.
The result looks like this: Values form line 2 are copied at the end of line 1. You can now delete the second feature:
Refactor fields dialog window: the joined attributes coming from layer
X in the
joined layer are copied so that the values of the 2nd feature will be copied as new attributes with the prefix
2_ to the first feature: