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

Calculate Difference Between Dates

Hi Everyone,

I want to figure out a way to calculate difference between dates columns below.

Here is my Data set below-

Number IdLoop Number:FOT DateLoop DateStatus
160030-0006TL17/26/20198/16/2019Open
160030-0006TL29/16/201910/16/2019Open
160030-0006TL310/26/201911/25/2019Open
160030-0006TL412/5/20191/4/2020Closed
206699-4001TL11/14/20202/13/2020Open
206699-4001TL22/15/20202/16/2020Open
206699-4001TL32/20/20202/22/2020Closed

 

I want to calculate No of days between Loop Date and FOT Date for each Number Id when there Status are Open only.

Example: For a Number Id below, TL1 is the first loop so Count of Days will be dash, For TL2: the count of days is calculated by the logic

TL2= Loop Date of (TL1) - FOT Date of (TL2)

TL3=Loop date of(TL2) - FOT Date of (TL2)

Number IdLoop Number:FOT DateLoop DateStatusCount of  Days
206699-4001TL11/14/20202/13/2020Open-
206699-4001TL22/15/20202/16/2020Open2
206699-4001TL32/20/20202/22/2020Closed4

 

I need the count of days like these:-

TL12 Days DifferenceTL24 days Difference TL3

 

Note :

  1. For each Number ID, there will be Loop number from TL1 to TL5 some times it can extend till TL10 too.
  2. I might also view this in a stacked Bar chart for visualization. 

Not sure how to proceed !

 

Please let me know if you have question.

 

Thanks in advance

3 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Load your raw data into a table, for example named  "Data". Then update the resident table like this:

Left Join(Data)
LOAD
  [Number Id],
  [Loop Number:],
  if([Number Id] = Previous([Number Id]),
    [FOT Date] - Previous([Loop Date]),
    '-')
as Duration
Resident Data
Order By [Number Id], [Loop Number:];

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

LP27
Creator II
Creator II
Author

Thanks Rob !

But I tried the same scripts which you shared, its not working properly. 

kindly see the output below - 

Number IDLoop Number:FOT DateLoop DateStatusDuration
160030-0006TL17/26/20198/16/2019Open21
160030-0006TL29/16/201910/16/2019Open30
160030-0006TL310/26/201911/25/2019Open30 10
160030-0006TL412/5/20191/4/2020Closed30 10
206699-4001TL11/14/20202/13/2020Open30 
206699-4001TL21/30/20193/11/2019Open-
206699-4001TL32/25/20192/28/2019Closed-
348167004TL11/18/20192/7/2019Open-
348167004TL22/14/20192/17/2019Open-
348167005TL32/20/20192/23/2019Open-
348167006TL43/5/20193/8/2019Closed-

 

There are dashes in last 6 rows of Duration's Column and for the number id = 160030-0006 in above table, In loop number TL3, it should display Loop date(TL2) 10/16/2019 - FOT date (TL3) 10/26/2019 = 10 days 

logic for duration should be Loop Date(T1) - FOT Date(T2) ...so on!

Also for the first appearance of Number ID it should be empty or dash.

Please let me know if you need additional information.

 

Thanks Rob! 

 

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Can you please post your script?

-Rob