Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
paul_scotchford
Specialist
Specialist

Using Lookup to set the value of a variable

Hi All,

I'm trying to lookup a field value based on a user selection, I am using Lookup() , but I'm guessing I'm doing something incorrect as I cannot see this working.

This is being used outside the context of a load, hence am I working outside the scope of this function requirement , I am trying to set the variable dynamically , see below...

=if(max(CalendarDate) = lookup('CurrentTo', '[Country Code]', GetFieldSelections([Country Code]) , 'DateNow'),1,0)

Thanks in advance

Paul

1 Solution

Accepted Solutions
sbaldwin
Partner - Creator III
Partner - Creator III

Hi, It will never work, lookup is a script function only, you'll need to think of a different way.

View solution in original post

7 Replies
sbaldwin
Partner - Creator III
Partner - Creator III

Hi, It will never work, lookup is a script function only, you'll need to think of a different way.

sunilkumarqv
Specialist II
Specialist II

Hi Steve,

lookuphttp://michaelandqlikview.blogspot.in/2013/06/qlikview-lookup-function.htmlhttp://michaelandqlikview.blogspot.in/2013/06/qlikview-lookup-function.html( fieldname, matchfieldname, matchfieldvalue [, tablename] )

Returns the value of fieldname corresponding to the first occurrence of the value matchfieldvalue in the fieldmatchfieldname.

Fieldname, matchfieldname and tablename must be given as strings (e.g. quoted literals).

The search order is load order unless the table is the result of complex operations such as joins, in which case the order is not well defined.

Both fieldname and matchfieldname must be fields in the same table, specified by tablename. If tablename is omitted the current table is assumed.

If no match is found, null is returned.

Example:

lookup('Price', 'ProductID', InvoicedProd, 'pricelist')

I occasionally have issues using this function - mainly as I try to avoid it anyway.  Couple of things from trial and error:

  • The field names with the ' ' literal wrapper.  DO NOT wrap them with [ ] inside the ' ' even if the field usually needs them.  It will confuse Qlikview and won't find your match.
  • As it says, should always use the tablename, as usually not trying to use the current table name.
Not applicable

Hey Paul,

Can you provide a little more details.

  • What value should the variable hold
  • Based on what condition

A sample file would also be very helpful.

Also as mentioned by Steve Lookup() can't be used on the Front-end.

Thanks

AJ

paul_scotchford
Specialist
Specialist
Author

Correct, Yes I found another way where I could avoid a lookup completely.

Thanks

mohan_1105
Partner - Creator III
Partner - Creator III

Hi Paul,

 

It would be great if you could tell me what is the way to write the expression. I'm facing the same issue

chris1987
Creator
Creator

Hi Paul,

I've had similar situations and ended using the Only() function:

e.g.

I needed to find the year from my MasterCalandar based on yesterdays date:

=only({<DateID={'$(=num(today())-1)'}>}[Acct Year])

So you can see that I'm returning [Acct Year] where my DateID is yesterday.

I'm sure you can adapt this quite easily to suit your needs?

Cheers

Chris

greenee
Contributor II
Contributor II

Thanks for the pointer Chris, 

I have a little table with NTNAME and Employee_Country, and used the following variables to detect Country of current user, so I could use in a show hide expression on a set of tables, where users in certain countries can only see certain columns.

v_OSUSER = OSUser() ;

v_User_Country =  only({<NTNAME={'$(=$(v_OSUSER))'}>}EMPLOYEE_COUNTRY) ;

Show hide condition = If ( Match(Upper($(v_User_Country)),'XXX','YYY')>0,1,0)

Regards Greenee