I want to calculate the sum of duration of related app
AnsweredHello,
I have an application "Task" in which I have a field "Duration" and a relation field that is linked to an application "Project".
I would like to create a Calculation field in "Project" that is the sum of all the "Duration" fields in linked Tasks but i don't have the "Sum of Duration" therein.
Hope someone can help because i need to know the time spent on a project easily.
Thanks a lot
-
Hi Rainer,
I am already using this "formula". Is it possible to calculate this duration but in a specific time?
So to know for example the duration of the 2016 projects (without erasing the current ones); make something like:
@sum of NameOfTheDurationField - @sum of NameOfTheDurationField [01/01/2015 - 31/12/2015]
To calculate just the duration of this year's projects. It is this possible? Do you know the "formula"
Thanks
Roger
-
Hi Roger,
yes that's possible - if you have a date field in your app where the duration field is in. But you can't do it with `@sum of` . What exactly do you want to be shown in your calculation field? Do you need the result for further calculations?
The code for getting the sum of durations for one specific year is:
var dur = @All of Duration;
var date = @All of date field;var sum2015 = 0;
for(var i = 0; i < dur.length; i++){
if(moment(date[i]).format("YYYY") == "2015"){
sum2015 +=dur[i];
}};
sum2015That code would show the sum for 2015 in number format (helpful if you need the number for further calculations).
The following code woud show the sums for both years as text:
var dur = @All of Duration;
var date = @All of date field;var sum2015 = 0;
for(var i = 0; i < dur.length; i++){
if(moment(date[i]).format("YYYY") == "2015"){
sum2015 +=dur[i];
}};
var sum2016 = 0;
or(var i = 0; i < dur.length; i++){
if(moment(date[i]).format("YYYY") == "2016"){
sum2016 +=dur[i];
}};"Sum 2015: " + sum2015 + " hrs \n" +
"Sum 2016: " + sum2016 + " hrs\n" +
"**Total: " + (sum2016+sum2015) + " hrs**"You would see this:
Sum 2015: 1000 hrs
Sum 2016: 80 hrs
Total: 1080 hrsIt's also possible to select on the fly what you want to see in the calculation field. You could add a catogory field "Show Year" before the calculation field with the options: 2015, 2016, both. And then in the code you could define what happens if an option is selected.
Rainer
grabowski.rainer@gmail.com
Please sign in to leave a comment.
Comments
7 comments