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: 
stephane1
Contributor
Contributor

Fonction if avec ou

bonjour,

comment faire pour que cette condition fonctionne if ([machine]='70443''40195''40202','VOP PANTHER USI PREPA COUV')as Secteur.

si je met qu'un numéro ça fonctionne if ([machine]='70443','VOP PANTHER USI PREPA COUV')as Secteur

merci

1 Solution

Accepted Solutions
OmarBenSalem

if ([machine]='70443' or [machine]='40195' or [machine]='40202',

'VOP PANTHER USI PREPA COUV')as Secteur.

View solution in original post

3 Replies
Andrei_Cusnir
Specialist
Specialist

Hello,

 

There is an official documentation [1] for the If() function. This function has only 3 parameters which are separated with ",". The Syntax of the function is the following one: if(condition , then [, else])

 

This first part is the condition

The second part is what needs to be done if the condition is True

The last part is what needs to be done if the condition is False

 

Additionally it is stated that the last parameter is optional and if it is not provided, then it will be NULL.

 

In your use case scenario the expression "if ([machine]='70443','VOP PANTHER USI PREPA COUV')as Secteur" is working, because:

  • There is only 1 "," so you have provided the condition and what value is going to be used if that condition is true
  • If the condition is not true then it will return NULL

The other expression:  "if ([machine]='70443''40195''40202','VOP PANTHER USI PREPA COUV')as Secteur" it is not working, because there are multiple separate values in the condition.

 

To resolve this issue, you will have to use the following expression:

if (
         
[machine]='70443',
        'VOP PANTHER USI PREPA COUV',
        if (
            
[machine]='40195',
            'VOP PANTHER USI PREPA COUV',
            if (
                
[machine]='40202',
                'VOP PANTHER USI PREPA COUV',
               
Null()
            )
        )
     )as
Secteur

 

This expression first checks if the value is '70443' and then assigns 'VOP PANTHER USI PREPA COUV'. If the value is not '70443', then the last part of the first if statement is evaluated. Here we do the same check for the next value '40195' and we repeat the process until we reach to the last value. If none of the 3 values matches the values that we have specified, then it will assign the NULL.

 

Here is the expression breakdown:

Please keep in mind that there might be other ways to implement the same outcome, however this is the one that I have tested that is working for now.

 

I hope that this information was helpful. If your issue was resolved, please mark it as solution to give further visibility to the topic for the other community members. Otherwise, if I have misunderstood the use case scenario, please elaborated in detail by providing additional information.

 

---

[1] https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ConditionalFun... 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂
OmarBenSalem

if ([machine]='70443' or [machine]='40195' or [machine]='40202',

'VOP PANTHER USI PREPA COUV')as Secteur.

stephane1
Contributor
Contributor
Author

Thank you