I am using QGIS 3.x and struggling with the labels and I would like to have some expression for setting the visibility of some layers based by scale.

enter image description here

How can I make some of them disappear?

I tried:

   if(@map_scale<2000) then ("fid" = 18) = NULL

where "fid" is my data attribute table column NULL - label invisible when scaling smaller than 2000.

It doesn't work

According to the answer below, I used the following expression:

  @map_scale<2000 AND FID = 12

and I see, that the label I wanted to disappear is displayed, whereas all others I want to keep are gone.

enter image description here

How can I turn it around?

  • You can set scale-depended label visibility in the label properties.
    – Erik
    Sep 22, 2020 at 11:58
  • First if you look at the description.(click on the second line of the context window visible in your picture) you will see that the expected result for this data defined override is 1 or 0 so trying an expression that output a null value wont work. Second if you look at the "if" syntax (should appear at the right of the expression string builder, you may need to click the "show help" button) you will learn the proper syntax for your if expression.
    – J.R
    Sep 22, 2020 at 12:07

1 Answer 1


You would have to combine the conditions (scale and FID in your example) and return a boolean. If true, the label is shown, if false it is not displayed.

@map_scale<2000 AND FID = 30

Which is the same as

if(@map_scale<2000 AND FID = 30, true,false)

The CASE statement might be more suitable than the IF if you have several distinct conditions.

That being said, this expression would be better located in the scale dependent visibility just above the show label section

  • It doesn't really work. When I enter the first formula, the only one label is visible - the label with the FID defined in the formula. The remain several labels under the same conditions are not visible. Applying your second formula there are no labels visible.
    – Geographos
    Sep 22, 2020 at 12:59
  • that's pretty much how you have defined the problem: display for a given fid for a specific scale. For the other features, you would have to define other conditions. That's when the case statement becomes useful: a condition for scale 1 and whatever other conditions, like the FID you have provided, another condition for scale 2, another condition for other FID, and a default condition
    – JGH
    Sep 22, 2020 at 13:09
  • Ok so how to make only this layer invisible, whereas the other are visible?
    – Geographos
    Sep 22, 2020 at 13:11
  • Layer? Forget about the expression and use the scale dependent visibility just above the show label section
    – JGH
    Sep 22, 2020 at 13:12
  • 1
    using OR would be required (a feature cannot have two fid..) if(@map_scale<2000 AND (FID=12 OR FID= 13),false, true). Read the help for the case syntax
    – JGH
    Sep 22, 2020 at 13:40

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.