Skip to main content
Participant
December 10, 2020
Answered

Create sums based on dropdown selection

  • December 10, 2020
  • 2 replies
  • 1246 views

Its a ledger form, and the dropdown is for a category of expense. There are options like Housing, Transportation, Household Goods, etc. I want to create a sum for each category of expenses in a summary list. So at the end of the form it shows each category and the total spent.

Can that be done?

 

This topic has been closed for replies.
Correct answer try67

I didn't see a paperclip in the original message, so I uploaded it to Google Drive. Hopefully this works.

https://drive.google.com/file/d/1qziupSxVkCmh8VacZDda94TAkDdWfHPB/view?usp=sharing

 

The idea is that the individual transactions entered on page 1 would total on page 2 based on the category field. Right now its a text field, but I will convert it to a drop down.

 

Let me know if that makes sense.


Thanks, I understand now. First of all, you should convert the category fields to drop-down, because if the user enters "Bill" instead of "Bills" the sum for the latter won't pick it up... If they can only select from a pre-determined list it's more likely to work correctly.

So let's take that example. Create a total field for Bills on page 2 and apply the following code as its calculation script:

 

var total = 0;
for (var i=1; i<=28; i++) {
	if (this.getField("categoryRow"+i).valueAsString=="Bills") 
		total+=Number(this.getField("amountRow"+i).valueAsString);
}
event.value = total;

 

You can easily adjust it for the other fields.

2 replies

try67
Community Expert
Community Expert
December 10, 2020

So you want the summary field to contain both the name of the selected item, and its price?

Participant
December 10, 2020
No, I want the total of all the transactions for each category. Just
numbers.

Shelley Stevens
lonestaralaskan@gmail.com
try67
Community Expert
Community Expert
December 10, 2020

I will join the requset above to see the file in question.
You can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.

Inspiring
December 10, 2020

Can you share a file or  a draft to see how it looks?