JavaScript to calculate the average of a column

I have my PDF file I'm trying to calculate the average in a column of fields.

My problem is that there are 7 areas, but all 7 can be omitted, so I think I need some sort of statement 'if' that would only count the number of fields containing values.  Then, somehow working in the rest of my calculation...

That's what I have so far...

(function () {}

Get all the field values, as numbers
var v1 = + getField("column.0").value;
var v2 = + getField("column.1").value;

var v3 = + getField("column.2").value;

var v4 = + getField("column.3").value;

V5 var = + getField("column.4").value;

var V6 = + getField("column.5").value;

v7 var = + getField("column.6").value;

var V8 = + getField("column.7").value;

Calculate the result and the value of this field
Event.Value = (v1 + v2 + v3 + v4 + v5 + v6 + v7) / the number of fields that have been filled;

})();

I'm pretty new to javascript. Any help would be greatly appreciated! Thank you

First of all, I woul write this function withou field reference to make it more universal, and then I have a funcion of document level so it could be used more than once in a PDF document and easily put into another PDF file.

function Avg() {}
average computer of the last non-empty field names
var sum = 0; sum of the fields
var number = 0; meter for non-empty fields
for (i = 0; i< arguments.length;="" i++)="">
iField var = arguments [i]; get the element of arguments passed
var fField = this.getField(arguments[i]).value;
If (!) isNaN (fField)))) {}
field is a number
If (fField.ToString ()! = ") {}
field is not null or empty
sum += Number (fField); Add to the sum
Count ++; County of increment
} / / do not blank end
} / / end of number
} / / end of loop iterative arguments
If (count! = 0) {}
calculate the average if there is one or more items on average
to return the sum / count; Returns the average
} else {}
return ";
} / / no end no average calculated
} / / end of function Avg

Your custom calculation script would then become:

Event.Value = Avg ("column. 0', 'column.1', 'column.2', 'column.3', 'column.4', 'column.5', 'column.6', 'column.7');

Tags: Acrobat

Similar Questions

  • Calculate the average of a report by column

    Hello ~
    I have several reports in several areas on a page. I have columns for the time, count, Total and average. I'm trying to understand how to calculate the average for the data that is displayed. For example:

    By time

    Time count Total average
    2 2 4
    5-2-10
    10-3-30

    -----
    17 7 44 6.2857


    What is happening now is that the app is on average each line first and then adding the middle column. Is there anyway to average the totals and not the lines?

    Thank you
    Deanna

    Published by: Dclipse03 on October 7, 2008 10:00
  • Calculate the average per slot?

    Hi Chaps,

    I am a beginner on numbers (almost everything on Mac I would say) and I need help to calculate average values.

    These are calculated values (column 2) taken on a specific time of the day (column 1).
    I managed to create a third using a built-in function to get the time slot (column 3).

    14:58:42

    235

    14

    14:59:42

    274

    14

    15:00:50

    7937

    15

    15:01:55

    5157

    15

    16:02:57

    1822

    16

    16:03:57

    207

    16

    Can please somebody see me step by step how to calculate the average by time slot as below?

    14

    254,5

    15

    6547

    16

    1014,5

    Kind regards

    Stone

    This can help you

    Assuming you data in a table named 'Data' and the information is summarised in another table (right) named "Summary".

    Select cell B1 in the summary table and then type (or copy and paste from here):

    = SUMIF(Data::C,a1,Data::B) ÷COUNTIF (Data::C, a1)

    shortcut for this is:

    B1 = SUMIF(Data::C,a1,Data::B) ÷COUNTIF (Data::C, a1)

    Select cell B1, copy

    Select column B, paste

  • Calculate the average value

    the data that I measured changed quickly, so I want to get the average value of the data

    Don't tell me to use mean.vi, I already know.

    and I got an idea that is to add data in a table every time, then the sum of all value data and take the line of result by the number of items

    but I don't know how to do this, anyone can build a simple vi to show me? Thank you

    I enclose my vi that uses mean.vi to the average value of calc, you can remove it and help in your path, thank you!

    Do not add your data in a table that grows forever. What a waste of RAM. To calculate the average, you only need to sum and N.

    Here is a simple code to accumulate the sum of the values in a shift register and divide by the number of add operations.

  • Filtering and calculate the averages for subsets of a table

    I have a 2D picture that comes out of a loop, and I need to calculate the average of the subsets corresponding to iterations 0-9, 10-19, etc...  In addition, I need to filter the values above and below acceptable limits before calculating the average.  Any suggestions for how to address the issue?

    Here are examples of code does exactly that. This post, looks like you need an upper limit as well. I'll leave that as an exercise for you.

  • Example to calculate the average of gemFire

    Yogesh Mahajan,

    I was browsing through your http://community.gemstone.com/display/gemfire60/Data+aware+behavior+routingpage.

    It has a link to an example explaining how to calculate the average sales.

    This link is not navigable. Could you please share the example.

    Thank you

    Hi Neeraj,

    Sorry for the inconvinince, if you look at the child pages, you will get all the examples:

    http://community.gemstone.com/display/gemfire60/function+for+OLTP+applications

    This one is to calculate avg: http://community.gemstone.com/display/gemfire60/Data+independent+parallel+execution+on+all+data+nodes

    I hope this helps.

    Yogesh

  • Calculate the average over the last 12 months

    Hello

    I am trying to calculate the average value per customer and per month from and including the month and 12 months back

    for example: 1 January 12 = average (agreed_rate) & (process_rate) average from February 1st, 11 'and 1st January 12'.
    February 1, 12 = average (agreed_rate) & (process_rate) average of 1 March 11 'and 1 February 12'
    March 1, 12 = average (agreed_rate) & (process_rate) average of 1 April 11 'and 1st March 12' etc.

    create table (test)
    cust_num varchar2 (5).
    month, date, time,
    number of agreed_rate
    number of process_rate);

    insert into test values ("A001", January 1, 11 ', 87, 65);
    insert into test values ("A001", February 1, 11 ', 56, 62);
    insert into test values ("A001", March 1, 11 ', 76, 88);
    insert into test values ("A001", April 1, 11 ', 45, 69);
    insert into test values ("A001", may 1, 11 ', 99, 65);
    insert into test values ("A001", June 1, 11 ', 98, 43);
    insert into test values ("A001", July 1, 11 ', 87, 70);
    insert into test values ("A001", August 1, 11 ', 43, 99);
    insert into test values (' A001', ' 01 - SEVEN.-11', 62, 32 ');
    insert into test values ("A001", October 1, 11 ' 89, 44);
    insert into test values ("A001", November 1, 11 ', 34, 65);
    insert into test values ("A001", December 1, 11 ', 87, 87);
    insert into test values ("A002", January 1, 12 ', 33, 65 ");
    insert into test values ("A002", February 1, 12 ', 56, 23 ");
    insert into test values ("A002', March 1, 12 ', 76, 46 '');
    insert into test values ("A002', April 1, 12 ', 67, 69");
    insert into test values ("A002', may 1, 12 ', 99, 33");
    insert into test values ("A002', June 1, 12 ' 89, 21");
    insert into test values ("A002', July 1, 12 ', 87, p. 77");
    insert into test values ("A002', August 1, 12 ', 69, 99");
    insert into test values ("A002', '' 01-SEP-12, 89, 32");
    insert into test values ("A002', October 1, 12 ', 43, 20");
    insert into test values ("A002', November 1, 12 ', 34, 56");
    insert into test values ("A002', December 1, 12 ', 77, 78");

    JAN-12 e.g. agreed_rate average = (33 + 87 + 34 + 89 + 62 + 43 + 87 + 98 + 99 + 45 + 76 + 56) / 12
    FEB-12 average agreed_rate = (56 + 33 + 87 + 34 + 89 + 62 + 43 + 87 + 98 + 99 + 45 + 76) / 12

    The results should be displayed per month (like the example above) and cust_num.

    Can anyone help?

    Thank you

    You must go to the current line, that is included as twelfths a form 11 months.
    If you round the result is 67,42 67,41 rather than. This is the result on all the cust_num.
    If you want to the result for each customer comment just the partiton of clause.

    SELECT      cust_num, month, agreed_rate
    ,      round (sum (agreed_rate) OVER ( --PARTITION BY  cust_num
                                    ORDER BY month
                       RANGE
                       INTERVAL '11' month
                       preceding
                       ) / 12,2) AS avg_agreed_rate
    FROM       test
    ORDER BY  month
    

    Partition on cust_num

    SELECT      cust_num, month, agreed_rate
    ,      round (sum (agreed_rate) OVER ( PARTITION BY  cust_num
                                    ORDER BY month
                       RANGE
                       INTERVAL '11' month
                       preceding
                       ) / 12,2) AS avg_agreed_rate
    FROM       test
    ORDER BY  month
    

    Published by: chris227 on 01.02.2013 01:51
    the corrected table name

    Published by: chris227 on 01.02.2013 01:52

  • HO to calculate the average in the Transient attribute?

    Hi experts,

    I created a transitional attribute in the employee table to calculate the average skills employee.
    Am able to get the sum of skills but dono how to calculate the average. Please help me in this problem.

    code to calculate the sum is

    public getEmpOverallRating() number + {+
    RowIterator comp = getEmpSkillView();
    Number sum = new Number (0);
    + all in (comp.hasNext ()) {+
    sum = sum.add ((Number) comp.next () .getAttribute ("Ratting"));
    +}+
    to return the sum;
    +}+

    Thanks in advance,
    Knockaert

    Set the default value of the transient attribute to type of expression with a value like SkillView.avg ("Rating") where SkillView is the VO.

  • PDF form field calculates the AVERAGE incorrectly

    I have a PDF form field which is defined to calculate the AVERAGE of the other 4 fields. Each of these other areas has its validation configured to allow only the values from 1 to 3.

    The average field is dividing the total by 4, even if a person completes only 2 fields. I thought THAT AVERAGE would count only the fields that have a value in them. But it is to see which ones are empty as containing a 0, even if it is an invalid value for this field.

    How can I fix? The client really wants to have up to 4 fields and an average of only those that are filled. I thought it was what average was supposed to do.

    Is there a way to tell Acrobat to ignore fields if their value is less than 1?


    I answered this question here: http://answers.acrobatusers.com/PDF-Form-Field-calculates-AVERAGE-incorrectly-q13211.aspx

  • How to calculate the average of the 1 d array?

    Could someone please help me, how can I calculate average of the 1 d array? For example, if the table 1 d - is [2, 3], I would get average = 2.5. Thank you very much!

    Use the average function. You can use the search or the quick menu to look for where you don't know where to find.

    Norbert

  • calculate the difference of unique column values

    I tried the info and the website to learn how to perform a "calculation difference" function on a single column (channel) of data.  For example if my data channel is a period of time to say the following: 100, 101, 99, 102, 100, 99...  I would like to calculate 100-101 101 - 99 then then 99-102 and so on for all the values.  How can I do this?

    Hi ranger,

    Looks like you're looking for the standard function "Calculate the disparity" ANALYSIS > basic math.

    Hope this helps,
    Ralf

  • PDF Acroform Javascript (WIN): Calculate the Date of next Tuesday

    03/06/10

    Greetings;

    I found a javascript script that will calculate the date of next Tuesday, but I can't seem to make it work in Acrobat Pro v8 (Acroforms).

    Any help / guidance you can provide is appreciated the most.

    Script:

    http://Christian.lassem.com/js/JavaScript-next-Tuesday/

    JavaScript to find next Tuesday?


    function find_date_of_next_tuesday() {}
    var today = new Date();
    today.setDate (today.getDate () + 1);
    While (today.getDay ()! = 2) {}
    today.setDate (today.getDate () + 1);
    }
    return (today.toDateString ());
    }

    Thanks in advance.

    You just need to call this function, and then use the string that it returns. What

    does not work, exactly?

  • Read TDMS - calculate the average

    Hello

    I have data I stored in a PDM file, I want to do some calculations, such as finding the average of all of my data.

    Successfully, I have read the PDM file and linked to a waveform graph, no problem on this part.

    However, I'm stuck trying to figure out how can I access data other than just to print them on a graph.

    How could I summarize all the values to find the average value?

    I am using LabVIEW 2010.

    Thank you.

    Use the Mean.vi function under the probability and statistics.  I'm guessing that you read a wave form and you may need to remove the values of Y by using the function to get the elements of waveform.  Display code if you get stuck.

  • Calculate the average column...

    Hi all

    I calculate average but is showing values null.

    Ex: Formula like this Total/4.
    But my equal sum = 3 then 3/4 = 0.75 but it display '0'. Then more than an amount equal to 4 it display OK valules.less 4 then it displays * "zeroes."

    Thank you
    Coint.

    Try this
    (Total * 1.00) / 4
    and in column properties > Format of data-> check "Override default data Format" and go to 2 decimal places

    Pls mark as correct

  • JavaScript to calculate the DEPOSITS REGULAR CALCULATOR

    Looking for a JavaScript calculator that calculates compound interest results with a base amount, annual interest rate (which allows the user to calculate monthly or annually), set the period of calculation, regular monthly deposit and interest rates. The user would have the opportunity to increase the annual deposits with Inflation and change compound monthly or annual interval.

    That is to say

    Basic amount: $30,000

    Annual interest rate: 3%

    Calculation period: 10 years

    Regular monthly deposit: $200

    Inflation rate: 3%

    Increase deposits annually with Inflation or not

    Compound interval monthly or annual

    JavaScript is a computer language, so we write their own code to perform a specific task. You will need to provide more information such as field names, preparation time, etc..

Maybe you are looking for