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

Min and max dates in the script

Hi

I need help on below problem:

Data:

Patient IDstart Date TimeEnd Date Time
3ta12p84/6/2018 6:004/6/2018 6:00
3ta12p85/6/2018 6:005/6/2018 6:00
3ta12p86/6/2018 6:006/6/2018 6:00
3ta12p87/6/2018 6:007/6/2018 6:00
3ta12p88/6/2018 6:008/6/2018 6:00
3ta12p811/7/2018 6:0011/7/2018 6:00
3ta12p812/7/2018 6:0012/7/2018 6:00
3ta12p813/07/2018 06:00:0013/07/2018 06:00:00

 

Problem Statement: I am trying to calculate the date difference for this patient to calculate the total hospital admission days. To calculate that i am considering patient's min start date and max end date and used the formula mentioned below:

sum(aggr(max({$<[Treatment_Status]={'Completed'}>}End_Date) - (min({$<[Treatment_Status]={'Completed'}>}Start_Date)-1),Patient_ID,Hospital_Name))

This formula is working fine. but my problem is that for some patients the treatment happens multiple times and this formula will consider the min start date and max end date regardless of multiple treatments happened in different months.

I want to calculate the total hospital admission days for each patient using min start date and max end date but if the month is changed then it should calculate accordingly.

 

Can anyone help?

1 Reply
sunny_talwar

May be you need to add Month to your Aggr() function?

Sum(Aggr(
Max({$<[Treatment_Status] = {'Completed'}>} End_Date) -
Min({$<[Treatment_Status] = {'Completed'}>} Start_Date) - 1
, Patient_ID, Hospital_Name, MonthFieldHere))