You are viewing limited content. For full access, please sign in.

Question

Question

Can a Value of a Field Total Value of Another Field Based on Checkbox?

asked on December 21, 2023

Hello, I am hoping someone can help me out with a formula. I want a value of another field to appear whenever a choice in a check box is selected. We want the value to be the same no matter which choice is selected or if multiple choices are selected but if no choice is selected, we want a “0” to appear. For example when they select choice 1 and choice 2 in the checkbox, the value in the total field will equal the value selected of the Sub Route 2 field.

When I use a single IF formula for only one of the choices, it works and returns a value of 21 which is what I want:

=IF(Table.Checkbox.Choice_1=TRUE,Sub_Route_2,0)

But when I try and do multiple IF formulas in conjunction with the OR formula, it returns a value of “1”:

=OR(IF(Table.Checkbox.Choice_1=TRUE,Sub_Route_2,0),OR(IF(Table.Checkbox.Choice_2=TRUE,Sub_Route_2,0),OR(IF(Table.Checkbox.Choice_3=TRUE,Sub_Route_2,0))))

 

 

0 0

Answer

SELECTED ANSWER
replied on December 21, 2023

There's a couple things to address here:

  1. IF needs to be outermost formula
    • OR returns true or false as the value, so if you put it on the outside you won't get what you want. In contrast, IF returns the values you define for true or false (i.e., you shouldn't have multiple IFs in this case)
  2. You're working with a table, which means you need to utilize the INDEX function
    • Table variables are multivalued, so if you reference the variable without indexing it would return all values not just the current row; you may not notice this with only one row, but it'll cause issues if you ever have multiple rows because checking one row would affect all the other rows 
  3. The = TRUE part is not necessary because the checkbox variable is already returning a true/false value that can be used directly in the calculation.

 

The first step is addressing the indexing. You don't want this to evaluate every row of the table, just the relative row, so you need to use INDEX in combination with the ROW() function.

The ROW() function, which is really only for use within a table or collection, retrieves the row number for the field with the calculation and this can be used to select the relative/associated values of other table variables in the same row.

INDEX(Table.Checkbox.Choice_1,ROW())

This will give you the true/false value for checkbox choice 1 only from the respective row.

Note that you can't use a single index function on multiple items at once, you need index around each individual selection/column you want to reference.

 

The next step is to account for all the options. Since you want it to appear if any of the boxes are checked, then you want an index function for each option, then you can put them all in an OR

OR(INDEX(Table.Checkbox.Choice_1,ROW()),INDEX(Table.Checkbox.Choice_2,ROW()),INDEX(Table.Checkbox.Choice_3,ROW()))

We've established that in this case the index function would be getting the true/false value, so this OR statement checks them each and returns true when it hits one that is true.

step is to evaluate the value, and since the calculation above would already return a single true/false value, we can just do the following where the OR statement above is inserted as the condition:

IF(OR(INDEX(Table.Checkbox.Choice_1,ROW()),INDEX(Table.Checkbox.Choice_2,ROW()),INDEX(Table.Checkbox.Choice_3,ROW())),Sub_Route_2,0)

Just be mindful to make sure your parentheses and commas are in the right places; I usually try to build the calculations out in pieces like this to make them more manageable.

0 0
replied on December 21, 2023

Thank you so much! This makes a lot of sense now and it worked.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.