Can you use a variable in the LOOKUP function...

Can you use a variable in the LOOKUP function for returnColumn?

I am having some trouble trying to use a variable as the returncolumn in a LOOKUP.

LOOKUP(lookupValue, tableName, lookupColumn, returnColumn)

I have a virtual column โ€œDefaultTeamโ€ that contains the name of a column in a table. Trying to use it like this:

LOOKUP([match], โ€œScheduleโ€, โ€œmatchnumโ€, [DefaultTeam])

When I try this, Appshet errors stating that I need exactly 4 arguments. If I substitute [DefaultTeam] for a literal such as โ€œRed1โ€ it works fine.

Do you see any way to do this?

0 4 1,084
4 REPLIES 4

How aboutโ€ฆ LOOKUP([_THISROW].[match],Schedule,matchnum,DefaultTeam)

It looks like the last 3 inputs must be โ€œconstant valueโ€ expressions, so I donโ€™t think you can dynamically set the return column like that. I think Aleksiโ€™s version will just look for a column called โ€œDefaultTeamโ€ in the lookup table.

@Aleksi_Alkio @Adam_Stone_AppSheet Thanks - as Adam mentioned it seems like you cannot use a variable in that position. I guess this is now a feature request! Here are the errors I get:

using: * [DefaultTeam] - it states I need exactly 4 arguments.

  • DefaultTeam - it states "Column Name โ€˜teamโ€™ in Schema โ€˜QMatch_Schemaโ€™ of Column Type โ€˜Numberโ€™ has an invalid app formula โ€˜LOOKUP([_THISROW].match],Schedule,matchnum,DefaultTeam)โ€™. Unable to find column โ€˜DefaultTeamโ€™, did you mean โ€˜DefaultTeamโ€™?

One square bracket is missing. Try LOOKUP([_THISROW].[match],Schedule,matchnum,DefaultTeam)

Top Labels in this Space