Calculated value in repeating table - InfoPath Dev
in

InfoPath Dev

Calculated value in repeating table

Last post 06-30-2011 06:17 AM by Gyancher. 14 replies.
Page 1 of 1 (15 items)
Sort Posts: Previous Next
  • 06-18-2007 12:23 AM

    Calculated value in repeating table

    I have form with repeating table (columns - Date, Amount, Type and Percent). Amount field is calculated based on the Type and Percent. So for each new row inserted after 1st row the new amount is amount (from previous row) * percent (from previous row) * value (depends on type - from previous row) ....... i have used preceding-sibling in my repeating table rules to do the calculations - it all works fine and the way i want. But now there is a small change - the first row amount should now be calculated from a field outside the repeating table. lets say the field (outside repeating table) is called 'OriginalAmount' - the first row amount field should now be then calculated as follows:

    OriginalAmount * Percent (specified in first row) * value (specified in first row in Type).

    The row after the first should then use the amount from previous row but use percent and value from the same row. How could i acheive this ?

    Soham Bhatt
  • 06-19-2007 02:14 AM In reply to

    Re: Calculated value in repeating table

    Hi Soham,

    Cool calcs! This is a nice little trick I like to use:

    (number(position() = 1) * FirstRowFormula) + (number(position() != 1) * AllOtherRowFormula)

    This results in only applying the FirstRowFormula where position() = 1, and then only applying the AllOtherRowFormula wherever position() != 1.  Gotta love those mathematical properties!

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-19-2007 11:12 PM In reply to

    Re: Calculated value in repeating table

    Hi Matt,

    Thanks for the help - your calcs makes sense but do not work -  the formula is correct and verified (see below what am i using) but the amount field do not get populated by the formula.

    The way i apply the formula is on the Repeating Table by making a rule where the type (drop down) is equal to to 1 - expression used in the condition is self::my:group2/my:TypeOfIncrease = 1 then set the value of Amount field to the the below formula.

    Formula - (number(position() = 1) * ../../my:OriginalAmount * (self::my:group2[1]/my:Percent)) + (number(position() != 1) * (preceding-sibling::my:group2[1]/my:Amount) * (self::my:group2[1]/my:Percent))

    Is it not working because i'm applying them in the repeating table rules? i also tried applying formula in the Amount field 's default value (of the repeating table) - but that does not recognise preceding-sibling .

    Where did i go wrong here?

    Also, how would the amount field get poplauted - on the selection of the dropdown or when i insert another row? i would like to get the field poplated by the drop down selection or text entered in percent field in the same row.

    Thanks Again

    Soham Bhatt
  • 06-20-2007 07:38 AM In reply to

    Re: Calculated value in repeating table

    Hi Soham,

    I'm not sure what the problem is.  I was able to get this to work with my sample form.  Have you tried using default value formulas instead of Rules?

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-20-2007 04:55 PM In reply to

    Re: Calculated value in repeating table

    Matt - default value formula does not recognise preceding-sibling. How did you approachw ith yoru sample form and how did the amount field get populated - by inserting new row or upon filling out any field in the same row? if you could detail your steps may be it might help.......thanks again
    Soham Bhatt
  • 06-21-2007 01:58 AM In reply to

    Hi Soham,

    Default value formulas do recognize preceding-sibling, maybe you had an XPath incorrect.  I have made a simple sample that demonstrates this in the attached file.  I think it should be pretty self explanatory, but let me know if there are any more problems.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-21-2007 09:56 PM In reply to

    Re: Calculated value in repeating table

    Thanks Matt - the form is simple and self explanatory but what i'm trying to do is the 2nd row show first column should have default total (from the other columns) + the value of the first column first row.

    The default value formula recognises preceding-sibling group but not the field.

    Would it be easier if i attached my form?

    Soham Bhatt
  • 06-25-2007 02:30 AM In reply to

    Re: Calculated value in repeating table

    Hi Soham,

    I can't debug forms from the forum for free (say that 10 times fast, haha), but if you would like to purchase some support credits we could solve the problem.

    http://www.qdabra.com/products_all.asp?cat=12

    For the preceding-sibling problem, you should use it to get to the previous sibling, and then go down to the node.

    ../preceding-sibling::my:GroupNode/my:TextNode

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-25-2007 09:45 PM In reply to

    Re: Calculated value in repeating table

    Matt,

    Your form is 50% of what i'm looking for (i.e 1st row to have fdifferent calculation and 2nd row and onwards to have different calculations) - which is working fine.

    The other 50 % is that from second row and onwards the field should also use previous row's field value (preceding-sibling) for calculations.

    below if the default value formula for the field2 (from your form) all i have added is the bold portion to use the preceding-sibling in its calculation for 2nd row onwrads.

    The formula is verified but the value comes to NaN (even for the first row) - how can this be wrong or where's the bug?`

    (number(count(../preceding-sibling::my:group2) = 0) * (../../../my:field1 + 10)) + (number(count(../preceding-sibling::my:group2) > 0) * (../my:field3 + ../preceding-sibling::my:group2/my:field2 + ../my:field4))

    Soham Bhatt
  • 06-28-2007 12:37 AM In reply to

    Re: Calculated value in repeating table

    Could anyone help and provide their expert advice?
    Soham Bhatt
  • 06-28-2007 04:17 AM In reply to

    Re: Calculated value in repeating table

    Hi Soham,

    I don't know what else to tell you.  Try working it out on paper first, and then translating each individual piece, one by one.  Get the most complicated piece working first, and then add in the other piece, and then continue adding untill you find the problem.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-28-2007 05:54 PM In reply to

    Re: Calculated value in repeating table

    Matt - All i'm saying is that i have tried working on the paper and individually with each field on the form to achieve the results. If the formula is verified why doesn't it work?

    Take your Form for example - you have tried to have one set of calculation on the first row of the repating table (field2 = x + 10). And from 2nd row onwards its the sum of both fields in the same row (field 3 + field 4).

    All i'm saying is try adding field2 value from first row to second [i.e. field 3 + field 4 + field2 (preceding-sibling)] - let me see how it goes because when i try that the field2 value comes to NaN (even  the formula is verified)

    Soham Bhatt
  • 12-06-2007 09:44 AM In reply to

    Re: Calculated value in repeating table

    Hi Matt,

    You seem to know a lot about InfoPath and I know very little.  I have a similar problem as Soham.  I'm not trying to do any calculations from the previous row but I want to create a rule to set the next fields value from a field in the previous row.

     I have a repeating table that has leg numbers for flight logs.  Each New row is a new leg.  I have placed a rule on the repeating table (not the field) that if the leg number is not equal to 1, to set the From Airport to the preceding To_Airport (you will always leave the airplane you just left).  My rule does nothing on leg one, as it should and it works for leg 2  but it always returns the same To_Airport value for From_Airport that was on leg 1 for the rest of the legs so something is wrong with my node section (I think).  Here is my formula.

    normalize-space(preceding-sibling::*/@To_Airport[1])   I've tried placing the rule on the To_Airport field and it brings nothing and won't store any information in the field if I choose from the dropdown lists.  Placing the rule on the repeating table has so far got me the closest to what I'm looking for.

    The rule is not getting past the first row's value.  Do you have any idea what I'm doing incorrectly?  I tried placing a position expression in each row to test the position and it always returns 1 but I do have a numbering default formula for the leg number on each row in the repeating table that is working.  It's formula is count(preceding-sibling::Flight_Leg/@Leg_No) + 1

    Thanks

     

     

  • 12-07-2007 03:15 AM In reply to

    Re: Calculated value in repeating table

    Hi sboyddyn and welcome to the forum!

     You were so close!  Try this:

    normalize-space(preceding-sibling::Flight_Leg[position() = 1]/@To_Airport)  

    I have attached a sample I came up with to figure it out.  Hope this helps!

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-30-2011 06:17 AM In reply to

    • Gyancher
    • Not Ranked
    • Joined on 06-07-2010
    • Madison, WI
    • Posts 4

    Re: Calculated value in repeating table

     this is great!! thank you so much. I was looking for something like this.

     I needed a formula to populate the value from a end field into the next table.
    As thanks I attached my form for you all.

Page 1 of 1 (15 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.