Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
tomf122
Contributor III
Contributor III

Nested if statement

Hey guys, 

I have the following current logic which counts certain movement types and displays them in a car chart. 

This is working perfectly for me.

count({<MVT={'311','201','312','411'},[Day/Eve]={'Eve','Days'},Numeric={'0','1'}>}MVT)

An issue i am having is within the data certain movement types are being doubled counted so i want to divided these by two. I want to divide the MVT types 311, 312 & 411 by two but having trouble doing so. 

Current attempt is below. 

if (count({<MVT={'201'},[Day/Eve]={'Eve','Days'},Numeric={'0','1'}>}MVT))*1

if ((count({<MVT={'311','312','411'},[Day/Eve]={'Eve','Days'},Numeric={'0','1'}>}MVT))/2

 

Not too familiar with expressions within Qlicksense so not sure what i am doing wrong. 

 

 

Labels (2)
1 Solution

Accepted Solutions
vchuprina
Specialist
Specialist

Open the presentation tab and click on Suppress Zero-Values

vchuprina_0-1651660921024.png

Regards,

Vitalii

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").

View solution in original post

4 Replies
vchuprina
Specialist
Specialist

Hi,

In Qlik IF function requires at list two parameters (condition, then) also you can add a third parameter (condition, then, else)

if(condition, then)

if(condition, then, else)

If you want just to divide the value in your expression, you can do it without if statement

count({<MVT={'311','312','411'},[Day/Eve]={'Eve','Days'},Numeric={'0','1'}>}MVT)/2

Also maybe it makes sense to use distinct to remove duplicates

count({<MVT={'311','312','411'},[Day/Eve]={'Eve','Days'},Numeric={'0','1'}>}Distinct MVT)

Regards,

Vitalii

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").
tomf122
Contributor III
Contributor III
Author

Hey, 

With the help of your solution I have been able to use the following:

if(match (MVT,'311','312','411')
, count({<MVT={'311','312','411'},[Day/Eve]={'Eve','Days'},Numeric={'0','1'}>} MVT)/2,

if(MVT = '201'
, count({<MVT={'201'},[Day/Eve]={'Eve','Days'},Numeric={'0','1'}>}MVT)))

The solution above is working for me but now it is bring in all MVT types even if the value is 0. 

This is causing hundreds of 0 values to flow through.

Is there a way to only to display the ones which hold a value on the bar chart?

Currently flowing through like this:

tomf122_2-1651658129719.png

 

Would like to display such as this like it did with original query which was being used:

tomf122_1-1651658098593.png

 

 

vchuprina
Specialist
Specialist

Open the presentation tab and click on Suppress Zero-Values

vchuprina_0-1651660921024.png

Regards,

Vitalii

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").
tomf122
Contributor III
Contributor III
Author

That is working perfectly for me now.

Thanks a mill for all your help