Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I need help calculating the earliest employee start date in a script file.
My data looks something like this:
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:
I have tried with the Min() function and Group by in the script but I can seem to get the desired result.
Any advice?
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;
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()).
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;
Thank you. This did the trick.
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
I am looking for a script based solution. From what I understand the aggr() function is chart only.