Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
New-Qlik
Creator II
Creator II

Date condition in chart Expression

Hello,

I need help in writing one expression in line chart.

if(DATE <= vMAXDate, sales, sales-trend)

Kindly let me now if any other information required.

Thanks

Avneet

7 Replies
sunny_talwar

What is the issue you are facing with the current expression?

Siva_Sankar
Master II
Master II

Attach a sample application. or the error you are getting with the expression.

What date format you are using?

New-Qlik
Creator II
Creator II
Author

condition says if date is <= max(date) then show sales

else sales-trend

my date is from 02.25.2016 to 02.08.2016

maxdate is 03.31.2016

so till 03.31.2016 it should show sales and for rest sales -trend.

but its displaying sales-trend value through out

jonathandienst
Partner - Champion III
Partner - Champion III

>>if(DATE <= vMAXDate, sales, sales-trend)

>>but its displaying sales-trend value through out

Because you are using naked fields (that is fields not inside an aggregation function like Sum(), Min(), Count()...). The DATE value is not unique in this context, so it is always evaluated as null, so the comparison evaluates as false and you get sales-trend as a result.

You need something like

=Sum(If(DATE <= vMAXDate, sales, sales-trend))

Or make sure that each line of the table/chart always has only one possible value of DATE.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
New-Qlik
Creator II
Creator II
Author

Thanks Jonathan ,

=Sum(If(DATE <= vMAXDate, sales, sales-trend))

its still displaying same values (sales-trend)

jonathandienst
Partner - Champion III
Partner - Champion III

How is vMAXDate defined? Have you tried the expression with a literal value instead of a variable (for testing your logic)? Are the date values strings or proper numeric date values?

I suggest you post a small sample qvw that illustrates your problem.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
New-Qlik
Creator II
Creator II
Author

problem is solved.

it was format issue. DATE was in YYYYMMDDHH

and maxdate  was YYYYMMDD

Thanks guys for you time.