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

Announcements
Mastering Change Data Capture: Read Now
cancel
Showing results for 
Search instead for 
Did you mean: 
MHarrell
Contributor II
Contributor II

Calculating Values within 24 hours of a Date and Time

Hello,

I am trying to calculate the total doses of medication a patient was given within 24 hours of being admitted to the hospital.  I have two fields, AdmissionInstant and MedicationAdministrationInstant, which return a date and timestamp in the form MM/DD/YY hh:mm:ss.  I need to calculate the sum of the medication dose where MedicationAdministrationInstant- AdmissionInstant <= 24 hours.  I know how to use interval to calculate the number of hours between the time stamps but I think I need to use set analysis in order to make my calculation of sum(MedicationDose) work.  It didn't seem to like an if statement where the interval was less than 25 hours. 

I have accomplished similar things when looking at an entire month.  I use this, for instance, to return the data for the same month in the prior year.  I know this example isn't doing the same thing I'm trying to do but this at least shows what I think I need to do.  I just can't get it to work.

AdmitDate={"=inmonth(AdmitDate,Date(vCurrentDateCutoff, 'M/D/YY'),-12)='-1'"}

Does anyone know how I would make this work for looking at a period of 24 hours after a time stamped event?

Thanks for any and all help!

1 Solution

Accepted Solutions
sunny_talwar

Do you have an id for each admission? If you do (let's call it AdmissionID), you can do this...

{<AdmissionID = {"=MedicationAdministrationInstant - AdmissionInstant <= 1"}>}

I am assuming that both MedicationAdministrationInstant and AdmissionInstant are both time stamps 

View solution in original post

4 Replies
sunny_talwar

Do you have an id for each admission? If you do (let's call it AdmissionID), you can do this...

{<AdmissionID = {"=MedicationAdministrationInstant - AdmissionInstant <= 1"}>}

I am assuming that both MedicationAdministrationInstant and AdmissionInstant are both time stamps 

MHarrell
Contributor II
Contributor II
Author

Thank you this worked!  I used the MedicationAdministrationKey which is unique to each time a patient is given any medication.  Can you help me understand why the calculation below doesn't work to make sure I'm using hours vs. days?

MedicationAdministrationKey={"=Interval(AdministrationInstant-AdmissionInstant,'h')<25"} 

This returns the total of all medication dosage, not just the values less than 25 hours.

 

sunny_talwar

Although you are designating a format to the difference, the underlying value of the difference is still in decimals.... so, 1 hour = 1/24, 2 hours = 2/24....  so, up until 599 hours, your statement will still be true.... 599 hours = (24 days and 23 hours)

Does that make sense?

MHarrell
Contributor II
Contributor II
Author

Yes that makes sense.  Thanks for your help!