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: 
Not applicable

Count with a variable as condition

Hi,

I'm struggeling to find a way to display a number of name per year according to a condition.

I have a number of line in my data file. Each Line is a personne,the year he have started and its result for the year

Example : If personne A have started in 2014 and a second person have started in 2015, I have

Name             Started_date     Result

Personne A     2014                 10000€

Personne A     2015                 60000€    

Personne A     2016                 60000€

Personne B     2015                 8000€

Personne B     2016                 48000€

What I would like to display is the number of people, each year (bar chart) that have meet their target.

In this case, compare to when they have started : first year : 10000€, second year : 30000€, Third year : 50000€

In this example , I should have on my bar chart

2014 : 1

2015 : 1 (A have met his target of 30000 but B have not met his target of 10000)

2016 : 2 (A have met his target of 50000 and B have met his target of 30000)

My question is how can I do that?

For now, I have done the following, using varaible:

1) Create a variable to calculate the age of the person

          vAge = 2016-year(Started_Date)

2) Then a second variable that check the target of the personn (according to his age):

          vTarget = if( $(vAge)>2,50000,if($(vAge)>1,30000,10000))

3) Then a third variable that check if the result of the person is above his target: If yes --> 1

          vOk = if((Result)>$(vTarget),'1')

4) To display the result, I'm using this function for the bar chart:

count(

{<Winner>={'1'}} Name

)

For now, the only result I have is a bart chart that count the number of Name each year, no mather if they have met their target or not. But I think I have made a lot of mistake using the variable.

Can someone please help me?

3 Replies
sunny_talwar

Are you doing this in the script to create a flag??

Not applicable
Author

No, I define all the variable in the variable editor. As example on picture. Is it mandatory to use the script?
Capture.JPG

Not applicable
Author

More detail :

When I display the variable vOk inside a table, it does work. (I get 0 or 1 depending if the condition in the variable (if((Result)>$(vTarget),'1')) is right or not.

But when I try to count of many 1 or 0 I have, it doesn't work. ? Any Idea