Calculation based on choices in a category or by outgoing related items
I would like to put up a little complex calculation.. based on the specific choices made in a category field and/or the title of some chosen outgoing related items. Well, we have a category field with the choice of different meals or related items, that have the following titles in another app: Lunch (Saturday), Dinner (Saturday), Breakfast (Sunday), Lunch (Sunday). If only the Lunch (saturday) is chosen, the value returned should be 20. If only the Dinner (saturday) is chosen, the value returned should be 35. If only the Breakfast (sunday) is chosen, the value returned should be 15. If only the Lunch (sunday) is chosen, the value returned should be 20. If more than one entry is chosen, the sum of the chosen entries should be returned. Is there any easy way, to solve this kind of calculation? Hugs, malthe :o)

  • It's amazing how everything is possible.. ! I actually just tried to see if another solution would work - if I use related items, then put the specific meal value into a value field in every single related item and then just use @ All of ValueFieldInRelatedApp - that makes it very easy to return a sum of the values, but then I need a value field in every item. Your way works very well and clean! Thanks again, I'm amazed! :o)
  • If related items fits better to your needs you can take the calculation in my last posting For a categories solution (if the category field is in the same app as the calculation field) you only have to change the first line: var rItem = @ NameOfCategoryField; If the category is in another app: var rItem = @all of NameOfCategoryField; Rainer
  • Cool man, thanks for the answers! :) I'm gonna try them out right away..! Well, I'm asking about a category choice or a related item choice, because I wasn't sure if there might only be a solution for one of them.. I think the best solution for my purpose would be to use related items from an app with items representing all the various meals.. (this gives better options for reports, etc.) - but if a calculation based on related items wouldn't be possible, then I could use a solution with categories instead, if that would make a calculation possible!
  • Hi Malthe, like Eduardo said, there is a shorter way. To define the values for the chosen related item you can use: var rItem = @all of NameOfTitleFieldInRelatedApp; var LuSat = rItem.indexOf("Lunch (Saturday)") >= 0 ? 20 : 0; var DiSat = rItem.indexOf("Dinner (Saturday)") >= 0 ? 35 : 0; var BrSun = rItem.indexOf("Breakfast (Sunday)") >= 0 ? 15 : 0; var LuSun = rItem.indexOf("Lunch (Sunday)") >= 0 ? 20 : 0; LuSat + DiSat + BrSun + LuSun The result is the value you wish for the related items. The term inbetween the quotation marks (like: "Lunch (Saturday)") must be totally identical to the to the titles of the related item. But I don't understand what want to do with the category field. Are the categories labels = the 4 titels of the related items? Can the user choose to click a category OR a related item? What should the result in the category look like: a combination of calculations on the catogories and on the related item? Or an IF calculation: IF no category is selected then value from the related item else value from category field? Rainer
  • Hello, Malthe I've used this recently. Yes, you can use category fields to assign values to a "Calculation" field. if (@CategoryField == 'Lunch (saturday)') {meal = 20;} else if (@CategoryField == 'Dinner (saturday)') {meal = 35;} else if (@CategoryField == 'Breakfast (sunday)') {meal = 15;} else if (@CategoryField == 'Lunch (sunday)') {meal = 20;} Well, the above solution will be valid for single selections. As you wish the sum based on possible multiple selections you will have to add a few ELSE IF possibilities. When you have a multiple selection "Category" field, Podio holds all options separated by commas based on the SELECTION order used by the user. In other words, the "Calculation" field output may vary depending on wich order the user used to make the multiple selection. Some examples: Lunch (saturday),Dinner (saturday),Breakfast (sunday),Lunch (sunday) Breakfast (sunday),Lunch (sunday),Lunch (saturday),Dinner (saturday) Both examples above should return the same sum values because both have 4 selections but they have been "clicked" on different orders. I am not a JS expert so there might be a smaller solution for this: if (@CategoryField == 'Lunch (saturday)') {meal = 20;} else if (@CategoryField == 'Dinner (saturday)') {meal = 35;} else if (@CategoryField == 'Breakfast (sunday)') {meal = 15;} else if (@CategoryField == 'Lunch (sunday)') {meal = 20;} // The below lines should work for multiple selections considering that the user made his selection always "clicking" from the first option thought the last option. else if(@CategoryField == 'Lunch (sunday),Dinner (saturday)') {meal = 55;} else if(@CategoryField == 'Lunch (sunday),Dinner (saturday),Breakfast (sunday)') {meal = 70;} else if(@CategoryField == 'Lunch (sunday),Dinner (saturday),Breakfast (sunday),Lunch (sunday)') {meal = 90;} //Now you should type more ELSE IFs to consider other selection orders. Have I made myself clear?
This question is closed.