I'm trying to write an expression to use in model builder that if the field is 0, it will find the max for the field and add 1 to it. What I have so far is "(max([!Version!])+1) if !Version! ==0 else !Version!". The version field has integers from 0 to 5 right now. The dataset gets appended to periodically and we want to update the version to be the next number. Ideally, we would want the expression to find the max and add 1 to it but only add that value to rows with a Version value of 0 or null.
1. Find the max for the Version field
2. Calculate only features with the version values 0 (or prefereably null) with the max value +1
A select by attributes could be used to only calc the rows we want but then it will only get the max of what is selected and not the whole dataset. I tried to use the Calculate Value tool in modelbuilder to just get the max value but it wasn't working correctly.
I believe !Version! in field calculator would represent each entry, calculating the max of that would only return itself.
by "that if the field is 0, it will find the max for the field and add 1 to it. " i'm assuming you mean:
that if an entry in the field is 0, it will find the max for the field and add 1 to it. ?
find the max for the field first then run the calculate field
I didn't realize that it would only grab the max of each entry and not the whole field. My workaround was to bring in the summary statistics tool then feed that table into the Get Value tool to find the max value. I used the output of the Get Value as an inline variable to use in the field calculator. Seems to be working as intended now.