Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
michael_luettge
New Contributor

If statement with variable won't work

Hello specialists,

I need help for a coding problem that I'm not understanding.

In my script I query the actual user with:

Let vBenutzer = QVUser();

Then I like to decide with a "IF" statement which text a second variable should have:

If(vBenutzer = 'XXX', 'EN', 'DE') as Language;

I have tried many versions of the "IF" statements but nothing works.

Please can every specialist give me support?

Thanks in advance!

Tags (2)
1 Solution

Accepted Solutions
MVP
MVP

Re: If statement with variable won't work

Do you have section access in the application? If not, you might have to use OSUser() instead of qvuser(). And the code you use need some correction as well, like:

Let vBenutzer = QVUser();  // Or, OSUser()

Let Sprache =If( vBenutzer = 'XXX', 'EN', 'DE') ;     

If Sprache = 'DE' then

     SET A1 = 'Title DE 1';

     SET A2 = 'Title DE 2';

end if;

If Sprache = 'EN' then

     SET A1 = 'Title EN 1';

     SET A2 = 'Title EN 2';

end if;

7 Replies
vishsaggi
Esteemed Contributor III

Re: If statement with variable won't work

Try this?

If( $(vBenutzer) = 'XXX', 'EN', 'DE')

michael_luettge
New Contributor

Re: If statement with variable won't work

Hello !

Sorry, but won't work. I receive the message "Error in Expression" if I change the statement to this:

If( $(vBenutzer) = 'XXX', 'EN', 'DE') as Language;

The cursor indicates the " , " as the problem and I don't understand why?

Can anyone give an advise?

Thank you in advance.

chinnuchinni
Contributor III

Re: If statement with variable won't work

Can you please post your script once.

michael_luettge
New Contributor

Re: If statement with variable won't work

Hello,

it's a short script until now. I like to check which user has opened the application. Then I like to decide in which

language should Qlikview shows the titles of the tables. But the script shows me an error in the first "if" statement

and indicates that the " , " should be the problem.

Let vBenutzer = QVUser();

If( $(vBenutzer) = 'XXX', 'EN', 'DE') as Sprache;

If Sprache = 'DE' then

     SET A1 = 'Title DE 1';

     SET A2 = 'Title DE 2';

end if;

If Sprache = 'EN' then

     SET A1 = 'Title EN 1';

     SET A2 = 'Title EN 2';

end if;

Thank you for every advise.

MVP
MVP

Re: If statement with variable won't work

Do you have section access in the application? If not, you might have to use OSUser() instead of qvuser(). And the code you use need some correction as well, like:

Let vBenutzer = QVUser();  // Or, OSUser()

Let Sprache =If( vBenutzer = 'XXX', 'EN', 'DE') ;     

If Sprache = 'DE' then

     SET A1 = 'Title DE 1';

     SET A2 = 'Title DE 2';

end if;

If Sprache = 'EN' then

     SET A1 = 'Title EN 1';

     SET A2 = 'Title EN 2';

end if;

michael_luettge
New Contributor

Re: If statement with variable won't work

Thank you a lot, that was the solution !

MVP & Luminary
MVP & Luminary

Re: If statement with variable won't work

In your case the variable contains a string and therefore you need single-quotes around it by calling them, like:

If('$(vBenutzer)' = 'XXX', 'EN', 'DE')

Beside this I assume that you rather need osuser() instead of qvuser() which is only available if you used section access with USERID.

Further I suggest to consider to use the function directly instead of creating an additionally variable which adds here no value, maybe in this way:

if(match(osuser(), 'User1', 'User2', ...), 'EN', 'DE')

- Marcus