Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
didine
Contributor
Contributor

Variable

Hello , i have a question please if you can help me .

I have table :

Cat. Produ. V1. V2. Target

Cat1. P1 30. 50. >

Cat1. P1 40. 30. <

Cat1. P2 60. 50. =

Cat2. P12 60. 50. >

Cat2. P12 60. 50. >

I want :

V1 =if produ like p1

,If (v1>v2 and target= '>' , 1 , 0)+ ....v1>v2 and target= '>' , 1 , 0)+

I for Produ variable v1 telle me

For produ how much i have true

I wante do it for cat like drile down (cat_produ)

But i cant

Van you help me

Labels (1)
1 Reply
zar
Employee
Employee

Hi!

I would suggest go with script approach, so you can create your field on back end:

DATA:
Load
[Cat]
    ,[Produ]
    ,[V1]
    ,[V2]
    ,[Target]
    ,[Dif_Sign]
    ,[Num_Target]
    ,IF ([Dif_Sign]=[Num_Target], 'True', 'False') as ConditionCheck
;
Load
[Cat]
    ,[Produ]
    ,[V1]
    ,[V2]
    // checking if V1 is < = < V2, the result will be -1 if negative, 0 if equal, 1 if positive. 
    //We add 2 so we can have 1,2,3 as our Numerical target
    ,Sign(V1-V2)+2 as Dif_Sign
    ,[Target]
    ,Match([Target],'<','=','>') as Num_Target //convert Target into numerical so we can compare easy. Convertin to '<' = 1, '=' = 2, '>' = 3
;
Load * Inline [
Cat, Produ, V1, V2, Target
 
Cat1, P1, 30, 50, >
 
Cat1, P1, 40, 30, <
 
Cat1, P2, 60, 50, =
 
Cat2, P12, 60, 50, >
 
Cat2, P12, 60, 50, >
Cat2, P13, 50, 50, =
]
;

zar_0-1674394667612.png

If you are lazy and prefer inefficient solution, just create a dimension like this:

=IF (Sign(V1-V2)=-1 and Target = '<', 'True',
IF (Sign(V1-V2)=0 and Target = '=', 'True',
      IF (Sign(V1-V2)=1 and Target = '>', 'True',
'False'))) 
zar_1-1674394935975.png