Calculated Nested IfElse?

Hello, we're using a module to track attendance. We use a points system and allow a certain number of bereavement days based on the relationship. I'm trying to calculate a field that will result the number of days allowed based on the dropdown value selected for the bereavement reason. I'm trying to result the number 3 for Parent, Child, and Sibling, and the number 1 for Mother or Father In Law, Grandparent, Grandchild, Daughter or Son In Law, and Brother or Sisten In Law. After reviewing a few other posts, I attempted a nested IfElse, but it is not working. I'm getting an error that IfElse requires 3 parameters which I thought I had covered in the formula. Any help is greatly appreciated. I will need to use this formula again to apply attendance points based on the dropdown vaule in the attendance type field as well.

ifElse($bereavementreason_c,"Spouse",3,ifElse($bereavementreason_c,"Parent",3,ifElse($bereavementreason_c,"Child",3,ifElse($bereavementreason_c,"Sibling",3,ifElse($bereavementreason_c,"Mother or Father In Law",1,ifElse($bereavementreason_c,"Grandparent",1,ifElse($bereavementreason_c,"Grandchild",1,ifElse($bereavementreason_c,"Daughter or Son In Law",1,ifElse($bereavementreason_c,"Brother or Sister In Law",1,0)))))))))

Parents
  • Hi Kristen Dougherty,

    Using lists is a cleaner solution:

    ifElse(isInList($bereavementreason_c,createList("Spouse","Parent","Child","Sibling")),3,ifElse(isInList($bereavementreason_c,createList("Mother or Father In Law","Grandparent","Grandchild","Daughter or Son In Law","Brother or Sister In Law")),1,0))

    Regarding the error you were getting and why:

    Looking at just the first ifElse as an example:

    ifElse($bereavementreason_c,"Spouse",3,ifElse($bereavementreason_c...))

    This ifElse contains four elements but expects three.

    The first element is just a field, not a logical argument.

    It appears that you meant the first two elements to be the content of the logical argument, so here is an example of what I think was meant:

    ifElse(equal($bereavementreason_c,"Spouse"),3,ifElse($bereavementreason_c...))

    I would expect your formula to look more like this:

    ifElse(
    equal($bereavementreason_c,"Spouse"),3,
    ifElse(equal($bereavementreason_c,"Parent"),3,
    ifElse(equal($bereavementreason_c,"Child"),3,
    ifElse(equal($bereavementreason_c,"Sibling"),3,
    ifElse(equal($bereavementreason_c,"Mother or Father In Law"),1,
    ifElse(equal($bereavementreason_c,"Grandparent"),1,
    ifElse(equal($bereavementreason_c,"Grandchild"),1,
    ifElse(equal($bereavementreason_c,"Daughter or Son In Law"),1,
    ifElse(equal($bereavementreason_c,"Brother or Sister In Law"),1,0)))))))))

    I hope this helps!

  • Patrick, 

    Thank you! I used your recommendation of lists instead of ifElse and it worked like a charm. Thank you for your help.

    Kristen

Reply Children
No Data