dereference a SELECT statement

I'm trying to only show a view if the current user has a SuperAdmin role.

My DB structure: https://app.quickdatabasediagrams.com/#/d/cQgIjj

IN(
"SuperAdmin" ,
SELECT(
Users[roles][role],
[email] = USEREMAIL()
)
)

 I'm getting error Unable to find column 'email' in the above expression. 

StephenSaid_0-1698502632806.png

I must be using dereferencing badly. 

Solved Solved
0 2 162
1 ACCEPTED SOLUTION


@StephenSaid wrote:

I must be using dereferencing badly. 


Correct.  That expression is not valid syntax.  Because [Roles] is an EnumList of Ref, you would need to implement a "two-tier" expression IF you want to use the role name to validate with.  An alternative is to hard-code the Role ID of the Role name.  I'll show both below

IN(
"SuperAdmin" ,
SELECT( Roles[Role], IN([Role ID], ANY(SELECT(Users[Roles],[email] = USEREMAIL() )))
)

 The ANY() function extracts the EnumList column, otherwise its a List of a List and the IN() functino can't operate on that.

The alternative...

IN(
"<<SuperAdmin Role ID here>>" ,
ANY( SELECT( Users[roles], email] = USEREMAIL()))
)

Since the Roles data is very static,  this works just as well as searching by the Role Name. 

View solution in original post

2 REPLIES 2


@StephenSaid wrote:

I must be using dereferencing badly. 


Correct.  That expression is not valid syntax.  Because [Roles] is an EnumList of Ref, you would need to implement a "two-tier" expression IF you want to use the role name to validate with.  An alternative is to hard-code the Role ID of the Role name.  I'll show both below

IN(
"SuperAdmin" ,
SELECT( Roles[Role], IN([Role ID], ANY(SELECT(Users[Roles],[email] = USEREMAIL() )))
)

 The ANY() function extracts the EnumList column, otherwise its a List of a List and the IN() functino can't operate on that.

The alternative...

IN(
"<<SuperAdmin Role ID here>>" ,
ANY( SELECT( Users[roles], email] = USEREMAIL()))
)

Since the Roles data is very static,  this works just as well as searching by the Role Name. 

@WillowMobileSys 

Thank you.

This is the expression I ended up with:

IN(
"SuperAdmin",
SELECT(
Roles[Role],
IN( [roleID], ANY(SELECT(Users[Roles], [email] = USEREMAIL() ) ) )
)
)

 I prefer this since it is more readable.

Top Labels in this Space