Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to use case when

Hi Friends,

How to use case when statement in Qliview.

Thanks & regards,

krish

6 Replies
krishnacbe
Partner - Specialist III
Partner - Specialist III

Hi,

You can use nested If  or Match function to achieve the CASE logic.

Not applicable
Author

could you give me more clarity on this

with examples?

alis2063
Creator III
Creator III

you can define case statement as below,

CASE expression

  WHEN value_1 THEN result_1

  WHEN value_2 THEN result_2

  ...

  WHEN value_2 THEN result_n

  ELSE result

END AS expression

krishnacbe
Partner - Specialist III
Partner - Specialist III

Let me know where you want to use the case statement. Is it in Script or in UI?

johnw
Champion III
Champion III

It really depends on what you're doing and where. As an expression in a chart, or to establish a field, you could use one of these approaches:

if(Field='A','something',if(Field='B','something else',if(Field='C','and another thing')))

pick(match(Field,'A','B','C'),'something','something else','and another thing')

Or you could add a field to your data model as a separate table:

Something:
LOAD * INLINE [
Field, Result
A, something
B, something else
C, and another thing
];

Or you could build a mapping table, and apply it in a subsequent load:

SomethingMap:
LOAD * INLINE [
Field, Result
A, something
B, something else
C, and another thing
];

applymap('SomethingMap',Field) as OtherField

Not applicable
Author

Thanks Bro