Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all. I have a tricky question, hopefully someone out there can help me.
I am trying to move a daily Headcount calculation into the Script because it is too slow in the front end.
My goal is to take my table UnitHeadcountTemp, which is every [HeadcountDate] * every [Personnel Area], and calculate the headcount for each row's unit and date, with a couple of other conditions.
I have joined everal tables into a single personHeadcountTemp table. Now I want to take each row of UnitHeadcountTemp, and count how many rows of personHeadcountTemp meet the right conditions. This can go in a new table UnitHeadcountTOTALS.
Here is my script so far:
Hi all
Thank for your help. I solved this by looping through dates, and on each loop loading to the new table a count of the other table, with the relevant conditions. This works now that the Count is only referring to one table. However it is very slow, so I am putting it aside for now.
Here is the working code FYI:
Perhaps this?
UnitHeadcountTOTALS:
Load
HeadcountDate,
[Personnel Area],
count( distinct [in personHeadcountTemp]) as [in personHeadcountTemp],
IF ( [Employment Status] <> 'Withdrawn'
and [Action Start Date] <= HeadcountDate
and [Action End Date] >= HeadcountDate
and [Position Start Date] <= HeadcountDate
and [Position End Date] >= HeadcountDate
, [Personnel Number])
) as Headcount
Resident UnitHeadcountTemp Group By HeadcountDate, [Personnel Area],
[Employment Status], [Action Start Date] , HeadcountDate, [Action End Date] ,[Position Start Date] ,
[Position End Date], [Personnel Number] ;
Usually it's much easier to resolve the start/end dates with a real date which is associated with a master-calendar. This could be done with an IntervalMatch. Afterwards you could use rather simple expressions like:
count(Employee) or count(distinct Employee) or maybe something like: sum(EmployeeFlag)
- Marcus
Hi all
Thank for your help. I solved this by looping through dates, and on each loop loading to the new table a count of the other table, with the relevant conditions. This works now that the Count is only referring to one table. However it is very slow, so I am putting it aside for now.
Here is the working code FYI: