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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Kaushik2020
Creator III
Creator III

Convert SQL case statement to qlik sense

I have a scenario in SQL where i am using below case statements.

count(distinct (case when ( (Reg_date between trunc(current_date-1,'MM') and current_date-1)) then con_id else null end)) New,
count(distinct (case when ( (Reg_date between add_months(trunc(current_date-1,'MM'),-1) and add_months((current_date-1),-1))) then con_id else null end)) Old,

Can anyone please suggest what will be the replacement of these in Qliksense ?

 

Labels (2)
1 Solution

Accepted Solutions
jonashertz
Contributor III
Contributor III

Let's see if I got this right this time. use monthstart, addmonths and today functions edit as needed if I didn't get it right. Also beware that Reg_date is formatted as a date otherwise use the date or date# functions.

result:
Load
     count(distinct if(monthstart(today()-1) <= Reg_date and Reg_date <= today()-1, con_id)) as New,
     count(distinct if(monthstart(addmonths(today()-1,-1)) <= Reg_date and Reg_date <= addmonths(today()-1,-1), con_id)) as Old
Resident source_table;

View solution in original post

1 Reply
jonashertz
Contributor III
Contributor III

Let's see if I got this right this time. use monthstart, addmonths and today functions edit as needed if I didn't get it right. Also beware that Reg_date is formatted as a date otherwise use the date or date# functions.

result:
Load
     count(distinct if(monthstart(today()-1) <= Reg_date and Reg_date <= today()-1, con_id)) as New,
     count(distinct if(monthstart(addmonths(today()-1,-1)) <= Reg_date and Reg_date <= addmonths(today()-1,-1), con_id)) as Old
Resident source_table;