2

I am trying to filter an attribute table in QGIS Print Composer based on the current active atlas feature:

I have a table with an "id" column with and some records that have these values in the "id" column:

048-
048-1
048-2
048-2i
048-2ii

My current atlas feature is 048-2 (i.e. @atlas_feature, 'ref' evaluates to "048-2")

I'd like the table to filter (show) only the records that contain "048-2" and may contain more characters after it, so it should filter to this:

048-2
048-2i
048-2ii

If I use the expression:

"id" LIKE attribute ( @atlas_feature, 'ref' )

I only get "048-2" which makes sense.

Filtering by

"id"  LIKE  '048-2%'

gets the results I need.

But how can I filter this table according to my need by using attribute ( @atlas_feature, 'ref' ? – or, where to put the "%" in the following expression?

"id" LIKE attribute ( @atlas_feature, 'ref' )

Thank you.

4

Found the answer. One had to add the "%" sign with a concat operator:

"id"  LIKE  concat(attribute ( @atlas_feature, 'ref'),'%')
| improve this answer | |
  • Sometimes it's easier to read by removing as many functions as possible. Not sure if the syntax works but something like this: "id" LIKE attribute(@atlas_feature, 'ref') + '%' – alexGIS Apr 6 at 21:56
  • The "+" operator is for values and did not work in this case. I guess we have to explicitly use "concat". – BMM Apr 9 at 16:05

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.