Trying to get the minimum value of a list of numeric records excluding the value 0. I found an example in StackExchange that looks something like this:
fieldX = min (filter (not_0, [!field1!, !field2!, !field3!, !field!]))
Code:
def not_0 (value):
Return value > 0
Tried in Pro, like this:
fieldX = MinimumValue(filter(not_0, [!field1!, !field2!, !field3!, !field!]))
Code:
def not_0 (value):
Return value > 0
But it doesn’t work because in the code block it’s an “invalid expression. No function was found with the name ‘MinimumValue’”.
I am not sure if it is because of the function filter or the script itself that causes the error.
Any idea on how to exclude the value 0 while still getting the minimum value? Thanks.
Solved! Go to Solution.
Hey @RudyJamet
I was curious if you've attempted the use of min() as well? I believe that MinimumValue is a custom function that is not recognized in Python as it uses min() instead. This has worked with my testing using fieldX = min (filter (not_0, [!field1!, !field2!, !field3!, !field!])), if you're comfortable with lambda functions as well, you could attempt this too, which would eliminate the need to use not_0: min(filter(lambda x: x > 0, [!field1!, !field2!, !field3!, !field!])).
If this doesn't work, let me know and I can check it out!
Cody
Hey @RudyJamet
I was curious if you've attempted the use of min() as well? I believe that MinimumValue is a custom function that is not recognized in Python as it uses min() instead. This has worked with my testing using fieldX = min (filter (not_0, [!field1!, !field2!, !field3!, !field!])), if you're comfortable with lambda functions as well, you could attempt this too, which would eliminate the need to use not_0: min(filter(lambda x: x > 0, [!field1!, !field2!, !field3!, !field!])).
If this doesn't work, let me know and I can check it out!
Cody
I used the lambda function in the expression and it worked perfectly.
Thanks Cody, and happy new year!
Great to hear, glad it helped! Happy New Year!