<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to create a unique list of selected values from a field, Python and SQL in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1291025#M67681</link>
    <description>&lt;P&gt;Are you copying the code exactly as it appears in the box from the chat box?&amp;nbsp; Your search cursor has some loops in it that are not formatted right, and if the indents aren't in there, it's not going to run right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
#geoprocesing layer creation

#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count &amp;gt; 2')
# Obtain list of TAZs
unique_taz_values = []
with arcpy.da.SearchCursor('SummerizedPoints', 'TAZ_REG') as cursor:
    for row in cursor:
        if row[0] not in unique_taz_values:
            unique_taz_values.append(row[0])
# Loop through the list of TAZs, selecting each group of the same TAZ each time
for taz_value in unique_taz_values:
#select the current value of TAZ
    arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
    if ("Exclude = 'Exclude'"):
#remove excluded
        arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
else:
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')

print("calculations complete")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should also be deleting your cursors when you're done to clean up memory, so at the end of this you would have something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 May 2023 13:12:04 GMT</pubDate>
    <dc:creator>Kara_Shindle</dc:creator>
    <dc:date>2023-05-19T13:12:04Z</dc:date>
    <item>
      <title>How do I create a unique list of selected values from a field? Python and SQL</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290746#M67675</link>
      <description>&lt;P&gt;What I am trying to do is to have create a list of unique TAZs from the data already selected and iterate over that list and subselect all the rows that have that taz then check if they have the&lt;BR /&gt;Exclude identifier in the Exclude field, if so then remove 1 from the number of points else don't, have that iterate until there are no more values left in the list,&lt;BR /&gt;I tried inputting the below code into a Chat bot and it came out with the second code block however&lt;BR /&gt;it produces an error provided and don't know if the syntax is right as I only started learning Python and SQL yesterday, could someone help me figure out how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I Gave&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
#geoprocesing layer creation
#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count &amp;gt; 2')
#obtain list of TAZs

code goes here

#loop through the list of TAZ's selecting each group of same TAZ each time
for value &amp;lt; count of unique TAZ's; value++
{
#select the current value of TAZ
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
if ("Exclude = 'Exclude'"){
#remove excluded
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
}
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')
}
print("calculations compleate")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")
&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Chat Bot&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
#geoprocesing layer creation

#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count &amp;gt; 2')
# Obtain list of TAZs
unique_taz_values = []
with arcpy.da.SearchCursor('SummerizedPoints', 'TAZ_REG') as cursor:
for row in cursor:
if row[0] not in unique_taz_values:
unique_taz_values.append(row[0])
# Loop through the list of TAZs, selecting each group of the same TAZ each time
for taz_value in unique_taz_values:
#select the current value of TAZ
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
if ("Exclude = 'Exclude'"):
#remove excluded
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
else:
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')

print("calculations compleate")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")&lt;/LI-CODE&gt;&lt;P&gt;Error Given&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 12, in &amp;lt;module&amp;gt;&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11294, in SelectLayerByAttribute&lt;BR /&gt;raise e&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11291, in SelectLayerByAttribute&lt;BR /&gt;retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;&lt;BR /&gt;return lambda *args: val(*gp_fixargs(args, True))&lt;BR /&gt;arcgisscripting.ExecuteError: ERROR 160144: An expected Field was not found or could not be retrieved properly.&lt;BR /&gt;Failed to execute (SelectLayerByAttribute).&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 18:11:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290746#M67675</guid>
      <dc:creator>GISDepartmentMFM</dc:creator>
      <dc:date>2023-05-18T18:11:31Z</dc:date>
    </item>
    <item>
      <title>How to create a unique list of selected values from a field, Python and SQL</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290738#M67678</link>
      <description>&lt;P&gt;What I am trying to do is to have create a list of unique TAZs from the data already selected and iterate over that list and subselect all the rows that have that taz then check if they have the&lt;BR /&gt;Exlcude identifyer in the Exclude field, if so then remove 1 from the number of points else dont, have that iterate untille there are no more values left in the list,&lt;BR /&gt;I tryed inputing the below code into a Chat bot and it came out with the second code block however&lt;BR /&gt;it produces an error providud and dont know if the syntax is right as I only started learning Python and SQL yesterday, could someone help me figure out how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I Gave&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
#geoprocesing layer creation
#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count &amp;gt; 2')
#obtain list of TAZs

code goes here

#loop through the list of TAZ's selecting each group of same TAZ each time
for value &amp;lt; count of unique TAZ's; value++
{
#select the current value of TAZ
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
if ("Exclude = 'Exclude'"){
#remove excluded
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
}
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')
}
print("calculations compleate")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Chat Bot&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
#geoprocesing layer creation

#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count &amp;gt; 2')
# Obtain list of TAZs
unique_taz_values = []
with arcpy.da.SearchCursor('SummerizedPoints', 'TAZ_REG') as cursor:
for row in cursor:
if row[0] not in unique_taz_values:
unique_taz_values.append(row[0])
# Loop through the list of TAZs, selecting each group of the same TAZ each time
for taz_value in unique_taz_values:
#select the current value of TAZ
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
if ("Exclude = 'Exclude'"):
#remove excluded
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
else:
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')

print("calculations compleate")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")&lt;/LI-CODE&gt;&lt;P&gt;Error Given&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 12, in &amp;lt;module&amp;gt;&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11294, in SelectLayerByAttribute&lt;BR /&gt;raise e&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11291, in SelectLayerByAttribute&lt;BR /&gt;retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;&lt;BR /&gt;return lambda *args: val(*gp_fixargs(args, True))&lt;BR /&gt;arcgisscripting.ExecuteError: ERROR 160144: An expected Field was not found or could not be retrieved properly.&lt;BR /&gt;Failed to execute (SelectLayerByAttribute).&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 18:13:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290738#M67678</guid>
      <dc:creator>GISDepartmentMFM</dc:creator>
      <dc:date>2023-05-18T18:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a unique list of selected values from a field? Python and SQL</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290753#M67676</link>
      <description>&lt;P&gt;It will be easier for folks to address your question if you format your code.&amp;nbsp; Please see these guidelines -&amp;nbsp;&lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_blank"&gt;https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 18:02:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290753#M67676</guid>
      <dc:creator>ChrisRingo</dc:creator>
      <dc:date>2023-05-18T18:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a unique list of selected values from a field? Python and SQL</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290759#M67677</link>
      <description>&lt;P&gt;thank you for the tip the formatting has be changed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 18:12:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1290759#M67677</guid>
      <dc:creator>GISDepartmentMFM</dc:creator>
      <dc:date>2023-05-18T18:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a unique list of selected values from a field, Python and SQL</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1291025#M67681</link>
      <description>&lt;P&gt;Are you copying the code exactly as it appears in the box from the chat box?&amp;nbsp; Your search cursor has some loops in it that are not formatted right, and if the indents aren't in there, it's not going to run right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
#geoprocesing layer creation

#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count &amp;gt; 2')
# Obtain list of TAZs
unique_taz_values = []
with arcpy.da.SearchCursor('SummerizedPoints', 'TAZ_REG') as cursor:
    for row in cursor:
        if row[0] not in unique_taz_values:
            unique_taz_values.append(row[0])
# Loop through the list of TAZs, selecting each group of the same TAZ each time
for taz_value in unique_taz_values:
#select the current value of TAZ
    arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', 'TAZ_REG = TAZ_REG.value')
    if ("Exclude = 'Exclude'"):
#remove excluded
        arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
#calculate the area of each point if excluded
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
else:
#if there are not any excludes
arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')

print("calculations complete")
#clear out slection
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should also be deleting your cursors when you're done to clean up memory, so at the end of this you would have something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 13:12:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1291025#M67681</guid>
      <dc:creator>Kara_Shindle</dc:creator>
      <dc:date>2023-05-19T13:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a unique list of selected values from a field, Python and SQL</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1291051#M67682</link>
      <description>&lt;P&gt;not sure why there is a replay with the post, but i am having a new issue where I&amp;nbsp; cant get a python variable into the SQL query&lt;/P&gt;&lt;P&gt;this is&amp;nbsp; the new code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
#geoprocesing layer creation

#repair the geometry
arcpy.management.RepairGeometry('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'KEEP_NULL')
print("fetures repaired")
#create points
arcpy.management.FeatureToPoint('USE_real_master_Martin_County_3_10_23_TAZ_CRA','PointsWithin', 'INSIDE')
print("points layer created")
#Summarize points and feture layer
arcpy.analysis.SummarizeWithin('USE_real_master_Martin_County_3_10_23_TAZ_CRA', 'PointsWithin','SummerizedPoints')
print("SummerizedPoints created")
#selections and calulations of the data
# add calculation field 
arcpy.management.AddField('SummerizedPoints','Area_Per_Point', 'DOUBLE')
print("Area_Per_Point feild created")
#cleaning data
#selection of all the condos
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'NEW_SELECTION', 'Point_Count &amp;gt; 2')
# Obtain list of TAZs
Unique_values = list(set(row[0] for row in arcpy.da.SearchCursor('SummerizedPoints', 'TAZ_REG')))
# Loop through the list of TAZs, selecting each group of the same TAZ each time
for taz_value in Unique_values:
    #select the current value of TAZ 
    sql_query = f"TAZ_REG = '{taz_value}'"
    arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', sql_query)
    if ("Exclude = 'Exclude'"):
        #remove excluded
        arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'REMOVE_FROM_SELECTION', "Exclude = 'Exclude'")
        #calculate the area of each point if excluded
        arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count! - 1)', 'PYTHON3')
    else:
        #if there are not any excludes
        arcpy.management.CalculateField('SummerizedPoints', 'Area_Per_Point', '!MFM_ACRES! / (!Point_Count!)', 'PYTHON3')

print("calculations compleate")
#clear out slection
del cursor
arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'CLEAR_SELECTION')
print("Program Done")&lt;/LI-CODE&gt;&lt;P&gt;The error, the error line is&amp;nbsp; arcpy.management.SelectLayerByAttribute('SummerizedPoints', 'SUBSET_SELECTION', sql_query)&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 10, in &amp;lt;module&amp;gt;
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11294, in SelectLayerByAttribute
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 11291, in SelectLayerByAttribute
    retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 14:36:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1291051#M67682</guid>
      <dc:creator>GISDepartmentMFM</dc:creator>
      <dc:date>2023-05-19T14:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a unique list of selected values from a field, Python and SQL</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1291083#M67684</link>
      <description>&lt;P&gt;Seems like it has an issue with your SQL query.&amp;nbsp; Your code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sql_query = f"TAZ_REG = '{taz_value}'"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See a working example below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;whereClause = "TAX_DIST = '" + str(taxDistrict) + "'"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why do you have a "f" at the beginning of your query?&lt;/P&gt;&lt;P&gt;Also I believe you need to rework your quotes.&amp;nbsp; I would suggest testing your query by adding a print statement after it - you may see that your quotes are not getting inserted as Text&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update:&amp;nbsp;&lt;/P&gt;&lt;P&gt;So testing this small bit of code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;taxDistrict = 12
whereClause = "TAX_DIST = '" + str(taxDistrict) + "'"
print(whereClause)&lt;/LI-CODE&gt;&lt;P&gt;I get this result printed to the console:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;TAX_DIST = '12'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also try building the query in ArcPro, switching to the SQL view &amp;amp; using that to help check your syntax.&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 15:15:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-unique-list-of-selected-values/m-p/1291083#M67684</guid>
      <dc:creator>Kara_Shindle</dc:creator>
      <dc:date>2023-05-19T15:15:05Z</dc:date>
    </item>
  </channel>
</rss>

