I have relationship with 2 tables
Table 1 - Process
Table 2 - Process History
Here the relationship is Id(Process table) and ProcessId(Process history table) I want to calculate the Average Networking days of all the processes.
For eg:
nwd = 0;
count = 0;
if(Process.Id = ProcessHistory.ProcessId && ProcessHistory.Status='Status 3') {
nwd += NWD(Process.CreatedOn, ProcessHistory.CreatedOn);
count++;
}
Expected result AverageNWD = nwd/count;
How can we achieve this?
In the script:
Using the script below will add a new field to the
Process
table -NetWorkingDays
. This field will contain the working days for each project (Id
). With this field in the dataset will be easier to calculate the average in the UI (something likesum(NetWorkingDays) / count(distinct Id)
The last part of the script (from inside out):
Create temporary table to calculate
min(CreatedOn)
fromProcess
table andmax(ProcessHistoryCreatedOn)
fromProcessHistory
table.ProcessHistory
is also filtered to include only records whereStatus = 'Status 3'
(both tables are aggregated perId
)Once the temp table is created we can create the final table that in which we will calculate the number of net working days using the NetWorkDays function. The
NetWorkingDaysData
table will have only two fields -Id
andNetWorkingDays
And the final step is to drop the
TempTable
- its no longer requiredIn the UI:
The same result can be achieved in the UI using the expression below. Just bear in mind that the UI approach might lead to higher resource consumption! Since all the calculations are on-the-fly (depends how big your dataset is)