2

I am trying to figure out how to streamline a formula I am using in ArcMap.

I am using the "select by attributes" tool in ArcMap to select rows based on the total number of rows in the target attribute table. Right now I am using a formula that requires that I look at the number of rows in the table, and then replace the words "number of records in table" with the actual number. Since I do this quite a few times every day, I am looking for a way to avoid having to look at the attribute table and type in the number of rows in my formula.

Here is the formula I am using. How could this be modified to count the number of rows?

MOD(OBJECTID+(2*(number of records in table/20))-0,(number of records in table/20))=0
3
  • 1
    Which format is your data stored in? Is it shapefile, personal/file geodatabase, SQL Server... ? You could try writing SELECT COUNT(*) FROM YourTableName directly in the Select By Attributes expression to get the number of records, however, this may not work depending on your data format.
    – FSimardGIS
    Commented Jan 17, 2019 at 23:12
  • Thanks for the reply! I will be using this inside of a Personal Geodatabase. I tried using SELECT COUNT(*) FROM YourTableName in the expression, however it does not seem to work. Commented Jan 18, 2019 at 0:37
  • 1
    MOD has to be used as an operator in Access, not a function, so I think you will have to try it this way: (OBJECTID+(SELECT COUNT(*)/10 FROM YourTableName)) MOD (SELECT COUNT(*)/20 FROM YourTableName)=0 Also don't forget to change both 'YourTableName' with your actual table name.
    – FSimardGIS
    Commented Jan 18, 2019 at 1:51

1 Answer 1

1

If using ArcPy is an option you can create a function then call the function every time you want to select:

def selectThem(feature_layer):
    import arcpy
    rowcount = int(arcpy.GetCount_management(in_rows=fc).getOutput(0))
    oidfield = arcpy.Describe(fc).OIDFieldName
    sql = "MOD({0}+(2*({1}/20))-0,({1}/10))=0".format(arcpy.AddFieldDelimiters(fc,oidfield), rowcount)
    arcpy.SelectLayerByAttribute_management(in_layer_or_view=fc, 
                                            where_clause=sql)

example

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.