Is there a way to create Case Statements? & nested calculations

Is there a way to use CASE (sql)? Cant find a way to use it.

and on the same note - is there a way to do nested calculations (ifelse inside ifelse) or any way around it?

Hi @Gal -

There is no CASE function but you can use nested ifelse.

Example:

ifelse({Readable_Response} = 'Strongly Agree',5,
ifelse({Readable_Response} = 'Agree',4,
ifelse({Readable_Response} = 'Neither Agree or Disagree',3,
ifelse({Readable_Response} = 'Disagree',2,
ifelse({Readable_Response} = 'Strongly Disagree',1,0
)))))
1 Like

Hi, I know i can do that, even without the other “if esle”
for example:

ifelse({Readable_Response} = 'Strongly Agree',5,
{Readable_Response} = 'Agree',4,
{Readable_Response} = 'Neither Agree or Disagree',3,
{Readable_Response} = 'Disagree',2,0)

What i am looking for is to insert another calculated filed inside the ifelse it is not letting me do it.
for example:

ifesle ( {Readable_Response} = 'Strongly Agree' AND {calculated field example} > 2 ,5,
{Readable_Response} = 'Agree' AND  {calculated field example} < 2, 4,0 
1 Like

you can do that as long as you keep the same aggregation level throughout.
In your example this means that {calculated field example} should not use aggregate functions such as SUM(), MAX() etc

1 Like

@darcoli Hi,
sorry for the late reply but it does not work with >2 as well.
how do you know what the aggregation level is

Hi @Gal - Can you please try Switch statement.

switch({Readable_Response}, 
               "Strongly Agree", 5, 
               "Agree", 4,
               "Neither Agree or Disagree", 3, 
               "Disagree",2,
               "Strongly Disagree",1,
               0)

Please see the documentation link - switch - Amazon QuickSight

Regards - San

2 Likes

@Gal Did @Sanjeeb2022’s solution work for you? If so, we’d love it if you could help the Community out by marking his reply as “Solution” (check box under the reply).

If you need any additional help, let us know. Thx! :slight_smile: