Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
NikVladi
Contributor II
Contributor II

if exists(field, 'value') then ... endif. Need a minimalistic working example.

I came across a construction in QV on the Internet:

if exists(field, 'value') then
...
endif

I applied it. There are no errors. But I don't see that it works at all. Could you give me a minimalistic working example. I know that exists is usually used when loading a table, but this is a different case.

Labels (1)
1 Solution

Accepted Solutions
NikVladi
Contributor II
Contributor II
Author

Thanks. It works. But you know what else works? Exists instead of FieldIndex. It's really funny.

Fruits:
Load * inline [
Fruit
Apple
Banana
Grape];

if Exists('Fruit','Banana')
trace Banana exists;
endif

if Exists('Fruit', 'Orange') then
trace Orange exists;
endif

if not Exists('Fruit', 'Orange') then
trace Orange does not exists;
endif

View solution in original post

4 Replies
Vegar
MVP
MVP

I believe exists() only works in load statements. Try FieldIndex instead.

Fruits:
Load * inline [
Fruit
Apple
Banana
Grape];

if FieldIndex('Fruit','Banana')
trace Banana exists;
endif

if FieldIndex('Fruit', 'Orange') then
trace Orange exists;
endif

if not FieldIndex('Fruit', 'Orange') then
trace Orange does not exists;
endif

 

NikVladi
Contributor II
Contributor II
Author

Thanks. It works. But you know what else works? Exists instead of FieldIndex. It's really funny.

Fruits:
Load * inline [
Fruit
Apple
Banana
Grape];

if Exists('Fruit','Banana')
trace Banana exists;
endif

if Exists('Fruit', 'Orange') then
trace Orange exists;
endif

if not Exists('Fruit', 'Orange') then
trace Orange does not exists;
endif
Vegar
MVP
MVP

That is funny.🤯

 

I will try your syntax. I've assumed the first parameter to be a field reference and not a string, but I notice you use stringsforr all parameters.

 

Me: Exists(Fruit,'Banana')

You: Exists('Fruit','Banana') 

 

If this is true, then it will my learning of the day. Thanks!

NikVladi
Contributor II
Contributor II
Author

Yeah, I decided to try it and it worked. You know, I think it's going to be a revelation for QlikTech in their entire history as well.