IF function to apply a number value from a EnumList

Tom11
New Member

Hello,

I could use some assistance with developing an IF() statement to calculate the values entered in a different column within the same table. Basically, I have column, AggravatingFactors which is a EnumList type and the following options are available:

None
Strong gang affiliations
Serious injury to victim
Victim is a Senior
Very young or disabled victim
Specific threats to witness or victim
Victim resides in household
Addiction issues
Current emotional state

I need to calculate the values of AggravatingFactors in AggravatingScore and the total score of AggravatingScore will not exceed 3. So, if the user selects just one of the available options, the score will be 1, if the user selects 2 of the available options the score will be 2, if the user selects 3 or more of the available options, the score will be 3. If the user selects โ€œNoneโ€, the score will be 0. Iโ€™m having trouble figuring out how to write this expression and I have two of these scenarios, so figuring this out will solve both problems. Thank you in advance for your assistance!

0 6 124
6 REPLIES 6

Steve
Platinum 4
Platinum 4

Maybe this?

IFS(
  NOT(IN("None", [AggravatingFactors])),
    MAX(LIST(3, COUNT([AggravatingFactors])))
)

See also:

Steve
Platinum 4
Platinum 4

Or just this:

MAX(LIST(3, COUNT([AggravatingFactors] - LIST("None"))))

If they donโ€™t choose any aggravating factors, or if they choose only None, the result is 0; otherwise, the number is the count of factors that arenโ€™t None, to a max of 3.

See also:

Thank you so much for your help, When I use either of the expressions you provided, they donโ€™t calculate correctly.

With, MAX(LIST(3, COUNT([AggravatingFactors] - LIST(โ€œNoneโ€)))), the score is always โ€œ3โ€ even if โ€œNoneโ€ is selected or no selection at all, seems to be defaulting to 3. If the user selects 1 to 3 options, the score remains 3, when the user selects a 4th, 5th, 6th, etcโ€ฆ the score increases by 1 and should have a max score of 3.

With, IFS(
NOT(IN(โ€œNoneโ€, [AggravatingFactors])),
MAX(LIST(3, COUNT([AggravatingFactors])))
)
If โ€œNoneโ€ is selected, no score will be counted even is the user accidentally selects other options, which is good, can prevent mistakes. But if the user selects 6 other options, the score becomes โ€œ6โ€ and the Max is โ€œ3โ€.

I tried to rewrite differently:
IFS(NOT(IN(โ€œNoneโ€,[AggravatingFactors])),COUNT([AggravatingFactors])),
IFS([AggravatingFactors]=1,1,
[AggravatingFactors]=2,2,
[AggravatingFactors]=3,3,
[AggravatingFactors]=4,3,
[AggravatingFactors]=5,3,
[AggravatingFactors]=6,3,
[AggravatingFactors]=7,3,
[AggravatingFactors]=8,3)
But have the same issue as the expression above. If โ€œNoneโ€ is selected, it will not count. But, if โ€œNoneโ€ is not selected, and all 8 other options are selected, the score becomes โ€œ8โ€ and the Max should be 3.

Again, thank you for all your assistance with this!

Whoops! My mistake! MAX() should be MIN() instead.

Yep, that seems to have done it. Thank you!!!

Tom11
New Member

That seem to have done it and I applied the same logic to the other scenario so solved both issues! Huge Thanks!

Top Labels in this Space