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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

show selected case in field

I have i table like this , i want to make a other table according th rule : For each item FILED 1, If it existes number of  U, then number of U, elso, number of S

INITIAL TABLE

FIELD 1FIELD 2NUMBER
1S7
1U6
2S5
2U-
3S4
3U9

FINAL TABLE

FIELD 1NUMBER
16
25
39

How to proceed? thanks in advance

4 Replies
Not applicable
Author

Table1:

LOAD * INLINE [

   FIELD 1, FIELD 2, NUMBER

   1, S, 7

   1, U, 6

   2, S, 5

   2, U, -

   3, S, 4

   3, U, 9

];

table2:

load [FIELD 1] as field1,[NUMBER] resident Table1 where [FIELD 2]='U' and NUMBER <>'-';

table3:

load [FIELD 1],[NUMBER] resident Table1 where [FIELD 2]='S' and not Exists(field1,[FIELD 1]  );

drop table Table1;

Concatenate (table2) load [FIELD 1] as field1,[NUMBER] resident table3;

drop table table3;

Not applicable
Author

Thank you very muche David, your solution looks like work, but could you explain me why  :

[FIELD 2]='S' and not Exists(field1,[FIELD 1]  )

???

Not applicable
Author

if i have seval column NUMBER : NUMBER 1 , NUMBER 2, NUMBER3 in the initial table, and for the final table, the rule is the same : If it existes number1 of  U, then number1 of U, elso, number1 of S ; If it existes number2 of  U, then number2 of U, elso, number2 of S ...

how to play?

INITIAL TABLE


 

 
FIELD 1
FIELD 2NUMBER1NUMBER2NUMBER3
1S7235
1U65618
2S57820
2U-5530
3S44477
3U9
 
 
--
4S5724
4U7--

FINAL TABLE


 

 
FIELD 1
NUMBER1NUMBER2NUMBER3
165618
255530
394477
47724
Not applicable
Author

This script is easier to understand than the one I wrote before,

Table:

LOAD * INLINE [

FIELD 1,    FIELD 2,    NUMBER1,    NUMBER2,    NUMBER3

1            ,S                ,7            ,23            ,5

1            ,U                ,6            ,56            ,18

2            ,S                ,5            ,78            ,20

2            ,U                ,-            ,55            ,30

3            ,S                ,4            ,44            ,77

3            ,U                ,9          ,-            ,-

4            ,S                ,5            ,7            ,24

4            ,U                ,7            ,-            ,-];

Table1:

load [FIELD 1],NUMBER1 as NUMBER1_U, NUMBER2 AS NUMBER2_U, NUMBER3 AS NUMBER3_U resident Table where [FIELD 2]='U';

join load [FIELD 1],NUMBER1 as NUMBER1_S, NUMBER2 AS NUMBER2_S, NUMBER3 AS NUMBER3_S resident Table where [FIELD 2]='S';

drop table Table;

Table2:

load *,

if(NUMBER1_U<>'-',NUMBER1_U,NUMBER1_S) AS NUMBER1,

if(NUMBER2_U<>'-',NUMBER2_U,NUMBER2_S) AS NUMBER2 ,

if(NUMBER3_U<>'-',NUMBER3_U,NUMBER3_S) AS NUMBER3

resident Table1;

DROP Table Table1;

drop fields NUMBER1_U,NUMBER1_S,NUMBER2_U,NUMBER2_S,NUMBER3_U,NUMBER3_S;