2

I am working with QGIS 3.8.1 Zanzibar.

I have a layer with Offshore Licenses holders. The attribute table has separate fields for "Participant 1", "Participant 2", ..., "Participant 13".

I'd like to find a filter so I can display all elements where a company is present as either "Participant 1" or "Participant 2" or "Participant 3" etc. I have used

"particip1" IN ('Company Name') OR "Particip2" IN ('Company Name') OR ...

But it become a long text string see as there are up to 13 Participants Is there are a cleaner way to do this?

  • 1
    I would rather say your data structure is weird ... making the filter lengthy ...why are your participants scattered in different fields ? – snaileater Aug 20 at 8:55
  • 1
    @snaileater I guess there's only one entry per field, so projects with several participants need several fields. – Erik Aug 20 at 8:56
  • 1
    Haven't tried this, it's just an idea: array_find(array("particip1","particip2",...),'Company Name') - maybe it works out? – Erik Aug 20 at 9:00
  • snaileater is correct... I did not design the attribute table.. it was downloaded from Government Authorities... I supose O could murge the entries in the different field to one field – user131678 Aug 20 at 9:02
  • Tried Eriks approach.. didn't work – user131678 Aug 20 at 9:08
2

You could create a new virtual field where you concatenate all of your "Participant field"

Then you use this new field to filter with an expression like :

"VIRTUAL_FIELD" LIKE '%Company Name%'

Be careful if some of the company name are close you could have some false positive (for exemple '%Company A%' will select "Company A" but also "Company Abroad" or "Company Acountant")

1

Similar to what user Erik said:

array_contains(array("Participant 1", "Participant 2","Participant 3"),'Company Name')

This should work.

Edit: If you have text before and after the company name, the solution is:

array_contains(array_foreach(array("Paticip1","Pasticip2"... etc ), @element like %Company%'),1)
  • I tried array_contains(array("Paticip1","Pasticip2"... etc etc),'%Company%'), because the participant fields have more information than just the Company name (equity for example) or the Company name varies slightly with suffixes (ltd, plc, or subsidiaries).. but it didn't seem to work... any suggestions – user131678 Aug 22 at 7:29
  • array_contains() works only with exact matches, as far as i know. So you need to use array_contains(array_foreach(array("Paticip1","Pasticip2"... etc ), @element like %Company%'),1) – nepluisse Aug 22 at 8:14
  • IT WORKS !! great, many thanks, I'm not familiar with the @element part of the filter, need to do some research – user131678 Aug 22 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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