Function with no logic - Help!

Folks,

Something is ending my sanity…

I have a table called “jabot” with a column “$sigla” (an acronym).
I have another table called “reflora” with a column “$sigla”

I build up a table, called “recursos” with a unique list of the “$sigla”, in both “jabot” and “reflora”.

Now, I want a column that shown if recurso.$sigla occurs (true) in “reflora.$sigla” and if occurs (true) in “jabot.$sigla”.

For recurso.$reflora, this works perfectly:

if $sigla in [r.sigla for r in Reflora.lookupRecords()]:
    return "true"
else:
    return "false"

But, withou logic, the same funcion do not work for the colum recurso.$jabot:

if $sigla in [r.sigla for r in Jabot.lookupRecords()]:
    return "true"
else:
    return "false"

Please tell me why!

image

The reason the text “false” is showing instead of checkboxes is because your jabot column isn’t set to the Toggle type.

If the problem is that all the results are false and none are true despite some matching values, we’d have to see what’s in Jabot.sigla. Is it the same column type as Recursos.sigla, i.e. Text and not something like Reference or Choice List?

The reason the text “false” is showing instead of checkboxes is because your jabot column isn’t set to the Toggle type.

It is not about that. I’m sorry if I wasn’t clear enough.

If the problem is that all the results are false and none are true despite some matching values, we’d have to see what’s in Jabot.sigla . Is it the same column type as Recursos.sigla , i.e. Text and not something like Reference or Choice List?

Yes. Both columns are “Text” and created with the function:

LEFT($dataset, FIND(" ", $dataset))

That’s precisely the point. Both columns, in “jabot” and “reflora” are exactly the same, and the function just work in one.

Can you share a document with the problem?

Sure! Send me your ID/email (in private?). Thanks!!

Can you make a new document with the same structure and make it publicly accessible to viewers only so that others here can see it?

Sure! Here we go:

https://docs.getgrist.com/gpc9bAj6ivMr/community

But there is no point to doing this because the problem just occurs in that specific document.

That’s why I asked for a support help. Again, I wasn’t clear enough. I’m sorry.

Try making a copy of the original document and slowly delete parts that don’t seem relevant. Keep deleting until you reach a point where the confusing problem is still visible but deleting any additional rows/columns/tables removes the problem (either by fixing it or by removing an essential component of what you’re trying to solve/demonstrate).

from what I saw there, it’s already working?

No. It is not. Not at my main document. Just in a copied document.

I don’t have “irrelevant” parts in my documents…

I’ll try something else. Thanks anyway.

Eduardo

I’m sure everything in the document is relevant to you, but it’s not all relevant to this specific question and the strangeness you’re seeing in your formula. Some ideas:

  • The Reflora table and the Recursos.reflora columns are working fine and aren’t required for the Recursos.jabot column, right? You can delete them from the copy and the problem should still be visible.
  • In the document you shared, Jabot only has one column sigla. So you can similarly convert the Jabot.sigla column in the copy from a formula to a data column, and then delete the dataset column as well as any others.
  • Is the problem still visible if you delete half the rows in the Jabot and Recursos table? Depending on what the problem is, you can probably even delete all rows except one.

Although I don´t understand what you mean with having no irrelevant parts in your documents, I understood now what you meant with “But there is no point to doing this because the problem just occurs in that specific document.”

So it’s very specific. When you copy the document, it works.

What happens if you export your document and import it to another document?

I assumed that directly duplicating the document still produces the same issue, and that the document Eduardo shared was an attempt to recreate the problem from scratch in a new document. Did I misunderstand? Was the shared document actually a copy that was then stripped down?

I’m still fighting. None of these functions work properly. Which one is the “most correct”?

if $sigla in Reflora.lookupOne(sigla=$sigla):
  return True
if $sigla in [r.sigla for r in Reflora.lookupRecords()]:
    return "true"
else:
    return "false"

$sigla in Reflora.lookupOne().sigla

I suggest:

if Reflora.lookupRecords(sigla=$sigla):
    return True

Thanks! I’ll try. And now with 20 characters :slight_smile: