Totals based on drop down selection - InfoPath Dev
in

InfoPath Dev

Totals based on drop down selection

Last post 11-20-2008 06:18 AM by punkn00dlez. 25 replies.
Page 1 of 2 (26 items) 1 2 Next >
Sort Posts: Previous Next
  • 11-17-2008 01:54 PM

    Totals based on drop down selection

    I'm making an expense report and to make it easier on the Accounting Dept, I'd like to assign codes to certain drop down menu selections.  Is there anyway I can create a total based on the selection in the drop down menu and palce it total in a box seperate from any others?

     In case I didn't explain it well here's an example:

    Date        Description            Category (this is the drop down)         Cost

    If category=A, total up catA's Costs in a seperate box, and so on and so on for all categories.

  • 11-17-2008 07:52 PM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Totals based on drop down selection

    Hi,

    Add expresion boxes to the form and add following function to expression box.

    sum(Cost[Category = "a"])

     

    Anuma Chinthapalli /
    http://www.GGKTech.com
  • 11-17-2008 11:04 PM In reply to

    Re: Totals based on drop down selection

    refer to the post : http://www.infopathdev.com/forums/t/9692.aspx

     you will get your answer...

  • 11-18-2008 07:00 AM In reply to

    Re: Totals based on drop down selection

    Unfortunately, I did not find my answer.  This is my first time ever using InfoPath, I really like using it, but things like XPath mean nothing to me right now.  Neither insturctions I followed helped me at all.  I've set each drop down menu choice with a unique value, but I don't know if that means anything or not.  I wish I could provide more information, but I just don't know how to explain well I guess.  Any questions you may have to help me I'll gladly answer.

  • 11-18-2008 07:16 AM In reply to

    Re: Totals based on drop down selection

    Are you using IP 2007 or 2003? If you are using 2007, you can right click on a field in the data source task pane and select 'Copy XPath' to copy the XPath to the clipboard. If you copy the XPath for the Category and for the Cost field and paste in a reply here, we should be able to give you the exact formula you need for your expression box to display the total based on the Category selected.

    Hilary Stoupa

  • 11-18-2008 08:49 AM In reply to

    Re: Totals based on drop down selection

    I'm using IP 2007. 

    The cost Xpath is /my:expenseReport/my:items/my:item/my:cost

    The category menu XPath is /my:expenseReport/my:items/my:item/my:category

    One thing I didn't think to ask before: Do I need to create unique fields in my Data Source menu for each option in the drop down?

  • 11-18-2008 09:03 AM In reply to

    Re: Totals based on drop down selection

    No, you don't need to create unique fields for each option.

    Think of the category field as a container. It is going to hold whatever your user selects from the drop down. The item they select will go into the category 'container' and stay there.... unless they change their mind and select a different option. Does that make sense?

    Per Anuma's earlier suggestion, you can add an expression box to your form to total the costs for the category. When you add the expression box, you'll be prompted to enter an XPath. Select the fx button to open the formula editior. I believe the following will do the trick:

    sum(/my:expenseReport/my:items/my:item/my:cost[../my:category = "A"]

    That will sum up all cost items where the category is equal to the letter 'A'. You can change the value in the quotes for your different categories, and add as many expression boxes as you need to display the totals.

    Hilary Stoupa

  • 11-18-2008 09:32 AM In reply to

    Re: Totals based on drop down selection

    Thanks! That one just looks like it'd work better than the other solutions. However, I get this error back:

    Expected value type: ,

    Actual value: end-of-string
    sum(/my:expenseReport/my:items/my:item/my:cost[../my:category = "86810"]<--

  • 11-18-2008 09:39 AM In reply to

    Re: Totals based on drop down selection

    That would be because my syntax was wrong -- I forgot the closing parenthesis!

    sum(/my:expenseReport/my:items/my:item/my:cost[../my:category = "A"])

    Hilary Stoupa

  • 11-18-2008 10:08 AM In reply to

    Re: Totals based on drop down selection

    Perfect! Thank you so much!  Quick question about the sytax though-why was it expecting a comma when you needed to place a close parenthesis?

    *EDIT

    Say I wanted to divide the output from the code above by another field to get a percentage, how would I go about that?  I tried the div operator, but it told me I needed a number.  There's no way I can use a constant, so what's the next step in figuring this out?

  • 11-18-2008 11:43 AM In reply to

    Re: Totals based on drop down selection

    So, when you tried this:

    sum(/my:expenseReport/my:items/my:item/my:cost[../my:category = "A"]) div my:expenseReport/my:otherField

    You had an error?

    As an aside, I have no idea why the error before suggested you needed a comma...

    Hilary Stoupa

  • 11-18-2008 12:08 PM In reply to

    Re: Totals based on drop down selection

    My error was generated because the way I tried it was completely and horribly wrong.

     The code you just posted shoots back one of 2 errors depending on how the expression field properties are set.  As a decimal, I get "-1.#IND" and as text I get "NaN".  These are showing up in design view when I see this.  The "-1.#IND" shows up when I switch to Form view until I tell it to calculate and both the NaN and the -1.#IND just calculate to zero no matter what.  I've tried some research on it, but I don't really know what I'm looking for so it makes it a bit difficult.  I think the "-1.#IND" has something to do with an indent maybe?  As for the NaN, I found some posts on here, but none seem to be terribly relevant.

  • 11-18-2008 12:29 PM In reply to

    Re: Totals based on drop down selection

    What field are you dividing by? Does it have a value?

    Hilary Stoupa

  • 11-18-2008 12:46 PM In reply to

    Re: Totals based on drop down selection

    I'm sorry to keep bugging you with simple stuff.  Here's my XPath code: sum(/my:expenseReport/my:items/my:item/my:cost[../my:category = "86810"]) div /my:expenseReport/my:items/my:total.  The field will only have a value once the submitter fills in a field named "cost".  Once that's there, the code above should execute and provide me with a percentage of the grand total.  I want to make a rule that'll run when cost is not equal to 0.00, but the only option I have under expression box properties is conditional formatting which won't get the job done.

  • 11-18-2008 12:59 PM In reply to

    Re: Totals based on drop down selection

    Nah, you aren't a bother at all. Everyone has to learn, and really, none of this stuff is all that simple.

    Let's see. There are ways to make a default value or an expression box value 'conditional' but they are a little complex. What about if you conditionally format the expression box so it only shows if cost is not 0 and total is not 0? That way you don't display the expression box when it might have an error because of total being 0 (a divide by 0 error) or it being blank....

    Hilary Stoupa

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