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

Calculate max date difference b/w dates

HI all,

I am having data like below.

Startdate,closedate,location

1/1/2021,2/1/2021,ind

4/1/2021,10/1/2021,ind

5/1/2021,7/1/2021,UK

8/1/2021,15/1/2021,uk

Based on the above data i want to calculate the maximum date difference between the dates based on location.

Could you please help me on the same

Labels (1)
6 Replies
Vegar
MVP
MVP

Try something like this:

Load

max(CloseDate-StartDate ) as DateDifference,

Location 

From Source 

Group By Location;

ksk278074
Contributor III
Contributor III
Author

Thanks for the reply.

 

I am not getting by using above script.

 

 

Vegar
MVP
MVP

Consider this sample script:

SET DateFormat='D/M/YYYY';
LOAD MAX(Closedate-Startdate) as DateDifference, Location
inline [
  Startdate, Closedate, Location
  1/1/2021,2/1/2021,Ind
  4/1/2021,10/1/2021,Ind
  5/1/2021,7/1/2021,UK
  8/1/2021,15/1/2021,UK]
Group By Location
;

 

PS: Qlik  Sense is case sensitive when it comes to values.  UK and uk are condisered as two different locations in Qlik Sense. In my sample above both UK are spelled with capital letters.

Vegar
MVP
MVP

If you want to do it in the application without pre-aggregations in the data you could try an expression like this.

=aggr(MAX(Closedate-Startdate), Location) 

or just 

=MAX(Closedate-Startdate)  

depending on how your objects are created.

ksk278074
Contributor III
Contributor III
Author

Thanks for reply.

 

If i want to do it on front end how can we do it?

 

 

Vegar
MVP
MVP

Take a look at the attached qvf file. There I show both script and in app solutions for your max difference problem.

Vegar_0-1631014384749.png