3

I have an existing vector layer (points) I was working on some time ago. The layer represents boreholes in the area of my interest (over 250 points).

Some time ago we got access to a number of geological documentations and my colleague updated some of the information regarding the boreholes in the Excel file. He used the same headers that I used in QGIS.

Is it possible in QGIS after adding a CSV or XLSX file for the join to fill in the missing gaps in an existing column rather than adding a completely new column?

For example, in the screenshot, you see a column named "do_str_wwy" - it represents the depth to the aquifer.

enter image description here

In the XLSX file, I have an identical column with completed values for the selected boreholes. What I want to accomplish is to fill in the NULL values in the existing column, because right now QGIS creates a whole new column every time and I don't know how it will handle this.

enter image description here

1
  • Do the join, use the field calculator to complete the pre-join fields with the joined field (if("field_x1" is NULL, "field_x2","field_x1")), then remove the join.
    – Erik
    Commented Oct 18, 2021 at 8:34

1 Answer 1

4

Using the examples you've shown, if you are using the Odwiert_na column as the key column to perform the join, you can use field calculator in your vector layer to overwrite the do_str_wwy column in one stroke with the following expression (replace new_layer_name accordingly). Note the use of single and double quotes

 attribute(get_feature('new_layer_name','Odwiert_na',"Odwiert_na"),'do_str_wwy')

This is essentially a lookup/join expression. This overwrites the entire column.

The structure works like this:

attribute(get_feature('other_layer_name','other_layer_matching_key_column',"current_layer_key_column"),'other_layer_desired_attribute')

get_feature() goes through your current layer's key column and grabs a matching feature (row) from the other layer based on matching values in the other layer's specified column.

attribute() then extracts the specific attribute from that matching feature.


Or if you want to keep the existing values in do_str_wwy in your vector layer, and only fill in values if the field is NULL,

coalesce("do_str_wwy", attribute(get_feature('new_layer_name','Odwiert_na',"Odwiert_na"),'do_str_wwy'))

coalesce() returns the first non-null value so if do_str_wwy has a value, it uses that, otherwise it applies the lookup expression.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.