Model Builder: Calculate Statistics for whole dataset and export into a single table.

312
2
Jump to solution
06-23-2014 07:13 AM
AlexanderShubra
New Contributor II
Good morning,

My goal here is to use the iterate tool and have the model run through each feature class(about 60+ feature classes) within a dataset, calculate the frequency/count of a ModifiedBy field & CreatedBy field and have the output be a single pivot table that is sortable by feature class, Modified By user & Created By user. I also need to it add the name of the feature class it pulled the statistics from.  We want to use this on a monthly basis to see how often people are updating each feature class.

I am running into issues with the interate tool over writing my statistics output table from the feature class before it.
so I need it to almost append the new values it created to a new table before it overwrites it and moves on to the next feature class.

Any help would be great.

Thanks,
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Hi Alexander,

Here is a script that will perform this functionality.  The script will iterate through each feature class in a geodatabase.  For the first feature class it will output the Frequency to a table called 'Report'.  Next, it adds a field ('FC_Name') to store the feature class name.  After the first feature class the script creates a table in memory of the frequency and then appends it to the table created previously.

import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\python\test.gdb"  firstTime = True  for fc in arcpy.ListFeatureClasses("*"):     if firstTime:         arcpy.Frequency_analysis(fc, "Report", "created_user;last_edited_user")         arcpy.AddField_management("Report", "FC_Name", "TEXT", "", "", 200)         with arcpy.da.UpdateCursor("Report", ["FC_NAME"]) as cursor:             for row in cursor:                 row[0] = str(fc)                 cursor.updateRow(row)         del row, cursor         firstTime = False     else:         arcpy.Frequency_analysis(fc, r"IN_MEMORY\Report", "created_user;last_edited_user")         arcpy.AddField_management(r"IN_MEMORY\Report", "FC_Name", "TEXT", "", "", 200)         with arcpy.da.UpdateCursor(r"IN_MEMORY\Report", ["FC_NAME"]) as cursor:             for row in cursor:                 row[0] = str(fc)                 cursor.updateRow(row)         arcpy.Append_management(r"IN_MEMORY\Report", "Report", "TEST")                 del row, cursor

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Alexander,

Here is a script that will perform this functionality.  The script will iterate through each feature class in a geodatabase.  For the first feature class it will output the Frequency to a table called 'Report'.  Next, it adds a field ('FC_Name') to store the feature class name.  After the first feature class the script creates a table in memory of the frequency and then appends it to the table created previously.

import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\python\test.gdb"  firstTime = True  for fc in arcpy.ListFeatureClasses("*"):     if firstTime:         arcpy.Frequency_analysis(fc, "Report", "created_user;last_edited_user")         arcpy.AddField_management("Report", "FC_Name", "TEXT", "", "", 200)         with arcpy.da.UpdateCursor("Report", ["FC_NAME"]) as cursor:             for row in cursor:                 row[0] = str(fc)                 cursor.updateRow(row)         del row, cursor         firstTime = False     else:         arcpy.Frequency_analysis(fc, r"IN_MEMORY\Report", "created_user;last_edited_user")         arcpy.AddField_management(r"IN_MEMORY\Report", "FC_Name", "TEXT", "", "", 200)         with arcpy.da.UpdateCursor(r"IN_MEMORY\Report", ["FC_NAME"]) as cursor:             for row in cursor:                 row[0] = str(fc)                 cursor.updateRow(row)         arcpy.Append_management(r"IN_MEMORY\Report", "Report", "TEST")                 del row, cursor
0 Kudos
AlexanderShubra
New Contributor II
Thank you for your help.
0 Kudos