1

I have a lookup table that contains a list of equipment along with an Elexon Charge code. I have already used the cascading select to sort equipment manufacturers and models, as these are presented as a drop down list, I am stuck with the next bit which is to automatically to fill in the Elexon charge code that is directly related to the model from the lookup table and make it un-editable, I have tried using the expression filter but that just gives a dropdown with all the codes in the table. I'm sure it is a simple fix but I just can't see the issue.

FormEquipment Lookup Table

3
  • Hi Stuart Venn, welcome to GIS SE. Such a question as yours would heavily profit from a screenshot or - even better -sample data for testing. It's much harder just from text to try to understand what you have and what you want to achieve.
    – Babel
    Nov 20 at 22:05
  • I assume you saying that Equipment Model should automatically determine Elexon Charge code? Is using a Virtual Field an option - that will just look up directly from the lookup table, and will auto populate based on the lookup value. Nov 21 at 3:33
  • Yes that is exactly what I am trying to achieve. Is there a way to use a expression filter instead of a virtual field.? Nov 21 at 19:28

2 Answers 2

1

One way is to use a Virtual Field.

With lookup data table as follows (layer named "data", lookup field is 'model', result field is 'code'):

enter image description here

I created a virtual field ('code') in my data entry layer with the following expression:

attribute(get_feature('data', 'model', "model"),'code')

So now as I enter the model for a new feature in the data entry layer, the code populates automatically:

enter image description here

The advantage of this method is that if the lookup table changes, the codes in the dependent table will also change.

2
1

One option is to use a Value Relation and Filter expression.

With lookup data table as follows (layer named "data", lookup field is 'model', result field is 'code'):

enter image description here

Then in the data entry layer, go to the Attributes Form and select the field to be looked up ('code' in my case).

  • Disable the Editable checkbox.
  • Select Value Relation
  • Select the same Key Column and Value Column - using the lookup result column from the lookup table/layer ('code' in my case)
  • Set the Filter expression using the lookup key column from the lookup table/layer ('model' in my case) to current_value('model')=attribute($currentfeature,'model') - note that the first field name relates to the data entry layer, and the second to the lookup layer.

enter image description here

Same result as for Virtual Field, but if for some reason you change the code mappings in the lookup table, it will stuff up your data in the data entry table. If you were going to change any mappings, you'd probably want to disable the Value Relation, and fix up any data before re-enabling it.

enter image description here

General approach taken from: Show ValueMap values based on value of another field in QGIS widgets, but yours is a simpler example.

Your Answer

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

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