Hi there.
I have this table of “collected plants”:
And I want to show the state that the species were collected, whit out repetition (“MG”). Just the “unique” values:
Is it possible?
Thanks!
Eduardo
Hi there.
I have this table of “collected plants”:
And I want to show the state that the species were collected, whit out repetition (“MG”). Just the “unique” values:
Is it possible?
Thanks!
Eduardo
To clarify, do you want the column Ocorrencia
to return a list of unique strings, so that it says MG, RJ
instead of MG, RJ, MG
?
It might be helpful to know what formula you’re using right now, but something like this should work:
values = <current formula returning list of strings>
return list(set(values))
A python set
cannot contain duplicate values, although it also loses the original order of values
. Converting back to a list makes it display nicely. You can also use sorted
instead of list
to sort the contents alphabetically.
Perfect! Thanks Alex! I know nothing about Python language. That’s may main limitation here…
Hi @alexmojaki ,
In the same context, is it possible to “CONCATENATE” two columns type “Choice List”?
I got this:
But I couldn’t show the result as a “List”
Thanks!
From Support Email:
Perfect! Thanks. But it goes “Red” on the margin. Probably because I can’t edit this column, right?
Hi Eduardo,
I’m not sure why you are seeing red. I tried to recreate by editing permissions within an example and was still able to concatenate the two choice lists. When you double click into the column, does it show an error message?
Feel free to share your document with support@getgrist.com and I can take a look.
Thanks,
Natalie
Hi @alexmojaki !
In this case, is it possible to sort alphabetically the “set”?
Thanks in advance!
Eduardo
Yes, using the sorted
function, e.g. sorted(set($B + $C))
Thanks Alex.
But it doesn’t work properly, using this:
values = [c.Taxa for c in Competencia.lookupRecords(Nome=$id) if c.Flora]+[c.Taxa for c in Competencia.lookupRecords(Nome=$id) if c.CNCFlora]
return list(sorted(set(values)))
I have this:
Sorry, only seeing this now.
You can combine those into one list comprehension:
[c.Taxa for c in Competencia.lookupRecords(Nome=$id) if c.Flora or c.CNCFlora]
but that’s not going to fix your problem.
I’m guessing that values
isn’t a list of strings at all, but rather a list of records, because Taxa
is itself a reference column and the formula column in the screenshot is a reference list. Is that right? If so then it’s sorting the row IDs which isn’t helpful. You need to access the strings in the formula itself by changing c.Taxa
to c.Taxa.Name
or whatever the column currently being displayed by the reflist is. Or use sorted(..., key=lambda t: t.Name)
if you want to keep it as a reference list. But then set
will only remove duplicate row IDs, not Taxa names.
Also, sorted
returns a list, no need to wrap in list
again.