If we reload the piece of script below
and we create a text box to show the value in the field Dim with the lowest Exp as sorting criteria, we get null as a result (see below), since there are two values with the lowest score according to the sorting criteria.
What can we do so we get one of the two values with the lowest sum(Exp)?
The function returns null because, when not using the distinct qualifier, the result is considered ambiguous since there are more than one value that could be returned as a result.
If we add the distinct qualifier to the function you will get the first of the possible values according to the load order. In this case 'A' will be returned (see below).
We can also modify the sorting expression and use "sum(Exp) + rand()" instead. In that case we will get randomly 'A' or 'B' as a result .