What’s the best way to set a column’s initial value to the column’s most common existing value? I experimented with various approaches and ultimately implemented the following, but feel like there must be a simpler technique.
In this example, I set the initial value for the Location column in the Events table to be the Location that is already the most common location across events.
Create a “Location Count” virtual column in the Events table to count the frequency of each event’s location:
So the MAX(Select… finds he highest count then the ANY(Select… finds the first [Location Code] which has this number. Not very elegant but should work.
Note that using a virtual column for this is going to get really expensive really fast. Consider wrapping the App formula expression for the virtual column with:
Hooray! Expression superhero @Steve does it again. Thanks a lot.
Somewhere along the way, I had tried a similar technique using [_THISROW], but hadn’t tried including the “-1”. I had assumed that [_THISROW] and [_THISROW-1] were equivalent in this context since there were only two levels of reference involved. If you have time at some point, it would be helpful to add here a conceptual explanation of your expression.
For those helped by referencing a concrete example, here’s an updated version using the Locations and Events scenario from my original post. See that I wrapped Steve’s expression in an INDEX() function to yield a single value for the column’s Initial value property rather than the list value that is the output of the ORDERBY() function.
I’ve deleted my virtual column since it’s no longer needed. Your idea to add a CONTEXT() condition to such columns is also helpful technique to keep in mind.
HI @dbaum , how is it that the second argument for the ORDERBY expression is a count expression?
The second argument for the ORDERBY expression is the sort-key.
sort-key - An expression that produces a sort key for the row. The sort key is compared against the corresponding sort keys of other rows to determine where the row will occur in the sorted list.
I don’t understand how a number could be a sort key.
A sort key is any value that can be compared with another value of the same type to determine whether one is less-than, equal-to, or greater-than the other.