Label Expression to filter data by latest date

775
4
06-25-2020 06:04 AM
MattWillcox
New Contributor

I am trying to write a python label expression which filters a column in my feature class so that its label shows a number from today's date. currently it labels every entry in the attribute table for the column in question. So for example if column A has a value of 1 and then changes to a value of 2 the next day I only want to show the value of 2. I can't seem to get a script which cracks it without issues.

Tags (2)
0 Kudos
4 Replies
XanderBakker
Esri Esteemed Contributor

Hi Willcoxm14 ,

Can you share what you have so far?

0 Kudos
MattWillcox
New Contributor

Hi Xander Bakker,

I might be well off with my code. I'm no expert, 

def FindLabel ( [CalcClass], [Date]):
def date(variable):
MaxDate = max([Date])
if (variable in MaxDate):
return True
else:
return False
Calc = [CalcClass]
Filt = filter(MaxDate, Calc)
for s in Filt:
return Filt

from using google I'm getting todays date by using the Max() function and then returning all values which are todays date in the date field (I think) and then using those to filter my CalcClass field. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Matt Willcox ,

When you use the FindLabel function you provide two parameters. Those are the attributes of the current feature. If you want to get the maximum date from a set of feature, you will need to connect to the datasource in the script and extract the values to perform the analysis that you need. Doing this can have a mayor impact on performance, since for every feature it will loop through features of a datasource. If you have many features this is likely to become very slow. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I agree with Xander Bakker‌ about performance.  For anything beyond a small to tiny data set, having a dynamic label based on a calculation over the whole data set will be slow at best.

0 Kudos