IF-AND Logic

I’ve Googled around and I can’t find anyone breaking down how to use a template field to stand in for IF-AND logic. Hoping someone can help me out:

I have two status with two options: going/not going, flying/not flying. How can I create the logic to say that if one of them is the positive (going/flying) then only display that one, and if both are positive, then display both? Oh, an if both are negative, display nothing, or a blank character.

Can you show a few examples of statuses and the expected results just to make sure I fully understand?

If User A is flying and going: Flying | Going
User A is flying not going: Flying
User A is not flying, and going: Going

You could break it down into a few columns, but I think a javascript column would be the easiest. Something like this:

function getStatus(isFlying, isGoing) {
  if (isFlying && isGoing) {
    return "Flying | Going";
  } else if (isFlying) {
    return "Flying";
  } else if (isGoing) {
    return "Going";
  } else {
    return "Neither";
  }
}


return getStatus(p1, p2));  

P1 would be the flying status and p2 would be the going status

Wasn’t even aware of the Javascript column! Thanks!

How would I make sure I’m comparing the field to a text value? Something like {isFlying} == “Flying” (since the column is human-readable text in both states)

So you are not using boolean columns?
How are the statuses getting set?

You could just use a template column by itself, but the problem with that is that you may end up with an extra slash or pipe character if only one status is filled. You could use an IF column to determine if there is a need for a separator, then combine value1, separator, and value2 in a template column.

The javascript can be modified but maybe not necessary. Is the goal only to combine two values together with a pipe or slash character, regardless of what the text is as long as it’s not blank?

You can do things with a template column, array columns, javascript, or a combination, but it all depends on all of the possible combinations we are working with. Now I’m thinking an IF column and a template column would be suitable.

Yeah, the template method is what I had originally thought would work, but I’ve never seen a tutorial on it or had it explained to me. They were originally text fields saying “Looking to Host” and “Not Looking to Host” (the other is for travel) but now they’re boolean. How would I set it up so the template field works the way I asked earlier?

I need to see your data. You mentioned text columns for the statuses, and now you mention boolean, so I’m not clear on the data that you are working with.

If you have text statuses, I would either use an IF column to determine if a separator is needed along with a template column to put it all together, or I would use javascript that checks the value names instead of booleans.

If you have booleans, I would use the javascript I provided earlier.

There’s several ways to approach it but it’s a lot easier to give a recommendation if I can see the data.

It took a bit of rummaging around, but your solution worked using the code you suggested for the Javascript column, thanks so much!

1 Like