Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

paul_scotchford
Valued Contributor

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

Tags (2)
1 Solution

Accepted Solutions
Highlighted
Partner
Partner

Re: Using Lookup to set the value of a variable

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

6 Replies
Highlighted
Partner
Partner

Re: Using Lookup to set the value of a variable

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

sunilkumarqv
Valued Contributor II

Re: Using Lookup to set the value of a variable

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

Re: Using Lookup to set the value of a variable

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
Valued Contributor

Re: Using Lookup to set the value of a variable

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

Thanks

Partner
Partner

Re: Using Lookup to set the value of a variable

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
Contributor

Re: Using Lookup to set the value of a variable

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