Issue using from_database in if

I am trying to pick a random value in a DataSet when the value of a column in another DataSet has a specifica value.

This is the formula:

if from_dataset("Base Items", "IsVariantEnabled", Code: baseItemCode) == '1' then this else nil end

If I use the from_dataset in a formula field it works as expected.

My Schema