Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
CasperQlik
Creator
Creator

First start date in Script

I need help calculating the earliest employee start date in a script file.

My data looks something like this:

CasperQlik_0-1683199589275.png

 

For various reasons employees can have multiple start dates. I need to get the earliest start date for all employees.

My data needs to look like this:

CasperQlik_1-1683199688187.png

I have tried with the Min() function and Group by in the script but I can seem to get the desired result.

Any advice?

 

Labels (5)
1 Solution

Accepted Solutions
_Iswarya_
Contributor III
Contributor III

Hi @CasperQlik 

Try the below script.

Temp:
load
emp_id,
Date(Date#(start_date,'DD-MM-YYYY'),'DD-MM-YYYY') AS start_date
inline [
emp_id, start_date
1001, 01-02-2018
1001, 01-03-2019
1002, 01-09-2001
1003, 01-02-1990
1004, 01-01-2016
1004, 01-05-2018
1004, 01-03-2020
];

left join(Temp)
Load
emp_id,
Date(min(start_date),'DD-MM-YYYY') as min_start
resident Temp
group By emp_id;

 

 

View solution in original post

5 Replies
Or
MVP
MVP

Using Min() and Group By sounds fine, assuming they're actually dates and note strings that happen to look like dates (otherwise, you should convert them to dates first using date#() and then use min()).

_Iswarya_
Contributor III
Contributor III

Hi @CasperQlik 

Try the below script.

Temp:
load
emp_id,
Date(Date#(start_date,'DD-MM-YYYY'),'DD-MM-YYYY') AS start_date
inline [
emp_id, start_date
1001, 01-02-2018
1001, 01-03-2019
1002, 01-09-2001
1003, 01-02-1990
1004, 01-01-2016
1004, 01-05-2018
1004, 01-03-2020
];

left join(Temp)
Load
emp_id,
Date(min(start_date),'DD-MM-YYYY') as min_start
resident Temp
group By emp_id;

 

 

CasperQlik
Creator
Creator
Author

Thank you. This did the trick.

Prem0212
Creator
Creator

you can use this function and i hope it works.

 

=aggr(Min(StartDate), Employee)

 

Please like and accept the solution if you find an answer

 

CasperQlik
Creator
Creator
Author

I am looking for a script based solution. From what I understand the aggr() function is chart only.