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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Kaushik2020
Creator III
Creator III

Case statement in Qlik

I have below SQL statement which I am looking for an alternative in qlik sense. 

 

count(distinct (case when (new_exist_flag='New' and (act_date between trunc(current_date-12,'MM') and current_date-12)) then co_id else null end))

I can use the count and distinct as part of Set expression from the UI. 

so here i want to see a conversion of SQL statement - case when (new_exist_flag='New' and (act_date between trunc(current_date-12,'MM') and current_date-12)) then co_id else null end

-> columns from table:

new_exist_flag, act_date, co_id

 

thanks in advance

Labels (2)
1 Solution

Accepted Solutions
Chanty4u
MVP
MVP

Try something like this

=count({<new_exist_flag={'New'}, act_date={">=$(=AddMonths(date(Today(), 'MM'), -12))<$(=date(Today(), 'MM'))"}>} DISTINCT co_id)

View solution in original post

2 Replies
Chanty4u
MVP
MVP

Try something like this

=count({<new_exist_flag={'New'}, act_date={">=$(=AddMonths(date(Today(), 'MM'), -12))<$(=date(Today(), 'MM'))"}>} DISTINCT co_id)

Kaushik2020
Creator III
Creator III
Author

thanks for the reply. it worked with a small change. 

~ Below shows previous month count. how we can modify this to qlik sense ? 

count(distinct (case when ( (act_date between add_months(trunc(current_date-1,'MM'),-1) and add_months((current_date-1),-1))) then co_id else null end)) ,