cancel
Showing results for 
Search instead for 
Did you mean: 

Calculated Attribute with if Condition

Former Member
0 Kudos

Hi All

  I am trying to create a calculated attribute age group for an age attribute for example if the age is between 30 -35 the age group column shoul have 30-35 as the age group corresponding to the record.I tried to create using IF condition but I am facing invalid expression error I am trying to put the condition as below

if("AGE" >=50 AND  <=55,'50-55') but it is not working .Request for help in creating the calculated attribute.

Regards

Santosh

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

This message was moderated.

former_member182277
Contributor
0 Kudos

Hello Santosh,

Please use the following expression:

if("AGE"  >= '35' AND "AGE" <= '40', 'yes', 'no')

you can replace 'yes' and 'no' with your requirement.

Here, Datatype of the "AGE" is NVARCHAR that why i used '35', if in case Datatype is "AGE" in INTEGER  the you can use 35 instead of '35'.

Please check this.

Hope it is useful.

Regards,

neha

Former Member
0 Kudos

Hi Neha

   The syntax is working fine when I activate it but my expression was being invalidated don't know the reason.Now I will try Case statement also to see how it works.

Thanks

Santosh

former_member182277
Contributor
0 Kudos

Hello Santosh,,

Can you write your expression what exactly you are writing and what is the datatype of the attribute.

Regards,

neha

Former Member
0 Kudos

Hi Neha

     I don't know why it was saying Inavlid expression but when I   activated the attribute view it did not throw any error , it gave the result as desired.now the below is working fine.I will try to replicate the same using CASE statement

if("AGE" >=20 AND "AGE" <=25,'20-25',

    if("AGE" >=30 AND "AGE" <=35,'30-35',

    if("AGE" >=35 AND "AGE" <=40,'35-40',

   

        if("AGE" >=40 AND "AGE" <=45,'40-45',

        if("AGE" >=45 AND "AGE" <=50,'45-50',

        if("AGE" >=50 AND "AGE" <=55,'50-55',

        if("AGE" >=55 AND "AGE" <=60,'55-60','60-65')

        )

        )

        )

        )

    )

    )

Thanks

Santosh

Former Member
0 Kudos

Hi Santosh,

Try this if("AGE" >=50 AND  "AGE" <=55,'50-55') instead.

Thanks,

Anooj

Former Member
0 Kudos

  Thanks for the reply, but the above syntax is also not workng ,when I saw the modelling guide the syntax is as below.I have multiple if conditions to use .I tried to replicate that but it did not work.

if("NETWR"<=500000,'A',

if("NETWR"<=1000000,'B','C')

)

Let us see what others say

Thanks

Santosh

Former Member
0 Kudos

Yeah you are right, you need to have the else condition specified as well.

if("A">=50 AND "A"<=55, '50-55',' ') worked for me - I was able to activate the attribute view successfully. I am assuming your calculated attribute is VARCHAR type with sufficient length to hold '50-55'.

Thanks,

Anooj

Former Member
0 Kudos

Hi Anuj

  Do you have 'AND' operator in operators list,because it is not present as operator for me I am inserting it manually.if it is there I am   thinking that could be the reason .Also can you confirm what is the data type of "A'' in your case.

Thanks

Santosh

Former Member
0 Kudos

Santosh,

I don't see AND as an operator. I just typed it in and it didn't complain. The column 'A' in my attribute view is of type INTEGER.

Also to note, I am on Revision 26 - not sure if that would make a difference in this case.

Thanks,

Anooj

Former Member
0 Kudos

Hi Anuj

     I don't know whya it was saying Inavlid expression but when I validate and activated it , it gave th result as desired.

now the below is working fine.Thanks for your help

if("AGE" >=20 AND "AGE" <=25,'20-25',

    if("AGE" >=30 AND "AGE" <=35,'30-35',

    if("AGE" >=35 AND "AGE" <=40,'35-40',

   

        if("AGE" >=40 AND "AGE" <=45,'40-45',

        if("AGE" >=45 AND "AGE" <=50,'45-50',

        if("AGE" >=50 AND "AGE" <=55,'50-55',

        if("AGE" >=55 AND "AGE" <=60,'55-60','60-65')

        )

        )

        )

        )

    )

    )

Thanks

Santosh