Counting, Adding and geting an Avg.. - InfoPath Dev
in

InfoPath Dev

Counting, Adding and geting an Avg..

Last post 04-13-2007 03:25 AM by B.Shiva Prasad. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 04-09-2007 07:34 PM

    Counting, Adding and geting an Avg..

    Hi there..

    I'm going to do my best to explain what has been driving me crazy for a few weeks know.. what i have is 4 text fields.. field1, field2, field3, field4 and i have field5(the one i want a function on).. so what i want to do is have the total of the field entered only, then the average..

    i have it so that it ads all the fields and gives me an average..
    so when i open the form and i enter the following field1 = 1 field2 = 2 field3 = 3 field4 = 4 i get 2.5 in field 5

    what i want is that if i entered field1 = " ", field2 = 2, field3 = 3 and field4 = 4 , field5 would give me the total of field2,field3,field4 and the average of those 3 not all 4..

    it seams simple to do.. but its not really..

    so i just want field5 to give me the total / average of the fields entered only.. can i do this.. if so how... please help me going crazy..
  • 04-10-2007 12:16 AM In reply to

    • Aruna
    • Not Ranked
    • Joined on 12-13-2006
    • India
    • Posts 17

    Re: Counting, Adding and geting an Avg..

    Hi redhead,

    One way to do this is, take one field “field1” in repeating section instead of taking four fields. After that repeating section display one field for average and do the following.
    Double click the average field and enter the following formula
    sum(field1[. != ""]) / count(field1[. != ""])

    If you want your schema as four fields like field1, field2, field3, field4 then you have to use ‘count#%92 function in code on those four fields when that field is not blank.

    Hope this helps you!
  • 04-10-2007 08:27 AM In reply to

    Re: Counting, Adding and geting an Avg..

    Hi So Sorry i'm not sure i understand how to do this..

    how do you create a “field1” in repeating section?

    what i did, was from the Insert Controls, i click on Repeating Section and added a field in there. then added a new avg box under it and added the formula above.. and i keep getting this error.. Node-test expected. sum(field1[. != ""]) / -->count<-- (field1[. != "])
  • 04-10-2007 08:39 AM In reply to

    Re: Counting, Adding and geting an Avg..

    Hi there i have added my form here so you can see what the mess i have created.. http://www.media705.com/test.xsn
  • 04-10-2007 12:00 PM In reply to

    Re: Counting, Adding and geting an Avg..

    This is funny but i got it to work.. but may i ask another question.. how do you add and sum up 2 groups

    sum(field1[. != ""]),(filed3[. != ""]) / count(field1[. != ""]), (field3[. !=""])

    what am i missing here?
  • 04-11-2007 04:07 AM In reply to

    • Aruna
    • Not Ranked
    • Joined on 12-13-2006
    • India
    • Posts 17

    Re: Counting, Adding and geting an Avg..

    Hi redhead,

    You can add and sum up two groups by using this formula:

    (sum(field1[. != ""]) + sum(filed2[. != ""])) / (count(field1[. != ""]) + count(field2[. != ""]))
  • 04-13-2007 03:25 AM In reply to

    Re: Counting, Adding and geting an Avg..

    Hi redhead,

    For getting total/average of the fields which does contain the values, and count of the fields which having values. Based on that the average will be counted.

    Use this formulae if you want the average except the fields which does not having the value.

    (sum(field1[field1 != ""]) + sum(field2[field2 != ""]) + sum(field3[field3 != ""]) + sum(field4[field4 != ""])) / (count(field1[field1 != ""]) + count(field2[field2 != ""]) + count(field3[field3 != ""]) + count(field4[field4 != ""]))
    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.