Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

CASE function

Is there a CASE function, or something similar to it in Qlikview? I use the CASE function in Salesforce and it's useful

Definition:   Checks a given expression against a series of values. If the expression is equal to a value, returns the corresponding result. If it is not equal to any values, it returns theelse_result
Use:  CASE(expression,​value1, result1, value2,​ result2,...,​ else_result) and replace expression with the field or value you want compared to each specified value. Replace each value and result with the value that must be equivalent to return the result entry. Replace else_result with the value you want returned when the expression does not equal any values.

9 Replies
anbu1984
Master III
Master III

There is no case statement in Qlikview. You can mutiple Ifs

If(expression=value1, result1,If(expression=value2,​ result2,else_result))

swuehl
MVP
MVP

Use something like

pick(1+match(FIELD,'Value1','Value2')

, 'Default'

, 'Result1'

, 'Result2'

)

sushil353
Master II
Master II

Hi,

You can use PICK() and MATCH() function

HTH

Sushil

Not applicable
Author

I had thought about this, but wasn't sure if it was a bit messy.

Can you use it in conjunction with the GetFieldsSelections function? It seems to product some funny results when I use a nested if

anbu1984
Master III
Master III

Yes.Can you post what you have tried?

Not applicable
Author

=if(GetFieldSelections(Region)='EMEA'

        ,NUM(SUM({$<[Business area]={'EMEA broking'}>}[Global Revenue £(000)s]*1000),'£#,##0')

        ,

        if(GetFieldSelections(Region)='APAC'

            ,NUM(SUM({$<[Business area]={'Asia pacific broking (excl china)'}>}[Global Revenue £(000)s]*1000),'£#,##0')

            ,

            if(GetFieldSelections(Region)='Americas'

                ,NUM(SUM({$<[Business area]={'Americas broking'}>}[Global Revenue £(000)s]*1000),'£#,##0')

                ,NUM(SUM({$<[Business area]={'Total global broking trading'}>}[Global Revenue £(000)s]*1000),'£#,##0'))))

swuehl
MVP
MVP

Try something like

pick(1+match(GetFieldSelections(Region),'EMEA','APAC','Americas')

,NUM(SUM({$<[Business area]={'Total global broking trading'}>}[Global Revenue £(000)s]*1000),'£#,##0'))))

,NUM(SUM({$<[Business area]={'EMEA broking'}>}[Global Revenue £(000)s]*1000),'£#,##0')

,NUM(SUM({$<[Business area]={'Asia pacific broking (excl china)'}>}[Global Revenue £(000)s]*1000),'£#,##0')

,NUM(SUM({$<[Business area]={'Americas broking'}>}[Global Revenue £(000)s]*1000),'£#,##0')

)

This would only work properly with one selected Region.

simondachstr
Luminary Alumni
Luminary Alumni

You can also use the SubStringCount() function for a better overview and easy of implementation.


See my example here:

http://community.qlik.com/docs/DOC-5841

al_king
Contributor
Contributor

It's worth revisiting this:

Now that we have Coalesce(), we can combine it with the standard If() function for a very flexible Case()-equivalent.
The key insight here is that the 'else' clause in an If() is optional, and if it's absent it returns Null().

As such, we can go:

Coalesce(

If(condition1, result1),

If(condition2, result2),

If(condition3, result3),

default)