I am using QGIS 2.18.19. I have a layer that shows 800+ different locations throughout the city. I want to randomly select say 30 locations using the Random Selection tool. It works great as is when there is no filter on. but once I apply a filter to the layer it would only select a random 10 locations even though I specified 30 in the "Number of selected features" box.

  • 1
    I tested this in QGIS 2.18.10 and in QGIS 3.0.2. It's a bug that exists in both versions. It doesn't look like anyone has reported this bug yet. You can make a bug report here: issues.qgis.org
    – csk
    Jun 27, 2018 at 18:24

2 Answers 2


The Random Selection tool doesn't seem to recognize when a layer is filtered. This is a bug. View the bug report to check the current status of this issue.

Here's a workaround using the Random Selection within Subset tool.

Use the Field Calculator to add a field a numerical field called "Filter" using the query expression. For example, if the filter query was "myfield" > 0, add a field like so: enter image description here

Now all the feature that would have been displayed with that filter, have a "Filter" value of 1. Features that would have been hidden have a "Filter" value of 0.

Run the Random Selection within Subset tool. Where it asks for an ID Field, select the "Filter" field.

enter image description here

Now it selects the desired number of features within the displayed features. It also attempts to select the same number of features within the hidden features, but those features are filtered out so it shouldn't affect any of the outcome.

Note: If you change the filter query, you must also update the "Filter" field.

UPDATE to bug report:

Fixed in master/backported to 3.2

-Presumably this means the issue is fixed in version 3.2, but will persist in earlier versions.

  • That worked, thank you so much for your help, I will report the bug as well, thrilled a newbie like me actually caught an untold discovery :)
    – shadyshawn
    Jun 27, 2018 at 19:42
  • great answer but your sreenshots are looking odd to my eye :(
    – LaughU
    Jun 28, 2018 at 13:32
  • @LaughU Blurry screenshots a problem I have with my home computer, probably due to some unusual screen settings. I hope you can see them well enough to get the information you need.
    – csk
    Jun 28, 2018 at 18:43
  • @user123049 I made a bug report before I saw your comment. Sorry to steal your thunder. Feel free to edit the bug report if you have anything to add. issues.qgis.org/issues/19276
    – csk
    Jun 28, 2018 at 19:24

Seems like the bug might be lingering in some form (V3.2.0-Bonn). I'm not actually using a filtered layer, but random selection would claim to select 50 polygons as requested, then only give me 45-48 (sometimes different with each run).

@csk's workaround still seems to work.

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.