Help me please with Lookup function

Hello community,

I have a problem with a formula that I attach below:

if(thisRow.Randomize = True(), Lookup(Questions, RandomItem(Questions.Question), Form.Category ), “”)

It is used in the form in the document I attach below:

And it is intended to randomly pick a question from a table of questions. At the moment it doesn’t return anything and I would ask someone to help me with this issue.

Hello @Alexandru_Grigoras ,

I can’t see your doc, but I notice the following:
if Randomize is a checkbox, you don’t have to add ‘= true’.
I think you should not use Lookup, but just RandomItem(ListOfQuestions)

Hello,

To help you understand why I included the randomization, please take a look at the document. I’ll publish it so everyone can easily see it.

I honestly don’t understand what you are trying to do - the form can work, but the question should become dependent on the category, but that also has the random formula in it. You probably want to filter the question based on the random category, but by the time it evaluates your formula, the category has not been filled yet.

So you really have to try something else - which is possible.

To answer your actual question - change the formula (for the question) to:

if(Randomize, RandomItem(Questions.Question), "")

When you hit the switch, the question will fill with a random choice from your table.

edit: changed the formula, it didn’t have the correct CFL

1 Like

Thank you for the response. I will clarify what I want to do:

I have a form, and I would like that when I press the randomize switch, a random category from the questions table appears in the category section. Considering that for a single category there are multiple questions, I would also like a random question from that category to be chosen at the same time, based on the randomly selected category. That’s why I used lookup. For example, if category 2 is randomly chosen, you can see in that table that there are 3 questions in category 2, and I would like one random question to be selected from those 3.

I understand what you are trying to do, but the way you have setup your answer table, you only have to make one random choice. The random choice of a ROW will include a category and a question.

That said, to make your current config work, you need the following two formulas

For category:

if(thisRow.Randomize, RandomItem(Questions.Category), "")

for questions:

if(thisRow.Category.IsNotBlank(),RandomItem(Questions.Filter(Category=thisRow.Category).Question), "")

I tried the formula, but I encountered an issue.

I think you are not using the correct Category columns - you have to check while typing what the options are and pick the right one, although Coda will often help:

The first one:
image

The second one:
image

Oh yeah, I see, thank you, I will try your tip and I will come back with an update. In the meantime, thank you very much for your help, you really helped me.


I don’t know what I did wrong, but still i don’t get any results.

I fixed it in your doc.

2 Likes

I really appreciate your help, thank you very much! Now is working perfectly.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.