Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Carlaf_93
Creator II
Creator II

SCRIPT

Good morning,

i've got a table like:

TABLE1:

CODE,

VALUE,

TYPE;

in this table i have a code (90000) that's zero.

I would like to give a value like:

if(code='90000' , sum({<TYPE='E'>}VALUE), sum(VALUE)) as VALUE;

 

How can i do it?

1 Solution

Accepted Solutions
Taoufiq_Zarra

it's because I didn't understand the request.

Maye be this its OK :

TABLE1:

LOAD * INLINE [
    CODE, VALUE, TYPE,YEAR
    1, 10, A,2020
    2, 20, E,2020
    3, 30, E,2019
    4, 40, A,2019
    90000, 0, P,2020
    90000, 0, P,2019
];
left join 
load YEAR,sum(VALUE) as SUM90000 resident TABLE1  where TYPE='E' group by YEAR;

OUTPUT:
noconcatenate

load CODE, if(CODE='90000',SUM90000,VALUE) as VALUE, TYPE,YEAR resident TABLE1;

drop table TABLE1;

 

output:

Taoufiq_Zarra_0-1612176427863.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

12 Replies
Taoufiq_Zarra

@Carlaf_93  in script ?

you want to replace all value by sum(Value) or Sum(Value of type E if code =90000) ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Carlaf_93
Creator II
Creator II
Author

yes, in the script area  to replace the sum of value where type is E in the code 90000

Taoufiq_Zarra

@Carlaf_93  Maye  be if you want to keep value for all avlue and sum() for 9000 like :

TABLE1:

LOAD * INLINE [
    CODE, VALUE, TYPE
    1, 10, A
    2, 20, E
    3, 30, E
    4, 40, A
    90000, 90, B
];
left join 
load sum(VALUE) as SUM90000 resident TABLE1 where TYPE='E';

OUTPUT:
noconcatenate

load CODE, if(CODE='90000',SUM90000,VALUE) as VALUE, TYPE resident TABLE1;

drop table TABLE1;

 

output:

Taoufiq_Zarra_0-1612174069414.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Taoufiq_Zarra

or replace all by sum like :

TABLE1:

LOAD * INLINE [
    CODE, VALUE, TYPE
    1, 10, A
    2, 20, E
    3, 30, E
    4, 40, A
    90000, 90, B
];
left join 
load sum(VALUE) as SUM90000 resident TABLE1 where TYPE='E';
left join 
load sum(VALUE) as SUMVALUE resident TABLE1 ;


OUTPUT:
noconcatenate

load CODE, if(CODE='90000',SUM90000,SUMVALUE) as VALUE, TYPE resident TABLE1;

drop table TABLE1;

 

output:

Taoufiq_Zarra_1-1612174129555.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Carlaf_93
Creator II
Creator II
Author

My data are like:

LOAD * INLINE [

CODE, TYPE, VALUE,

1,E,10,

2,P,23,

90000,P,0];

i would like to replace the value 0 in code 900000 with the sum(value) where type='E'

Taoufiq_Zarra

@Carlaf_93 

TABLE1:

LOAD * INLINE [

CODE, TYPE, VALUE

1,E,10

2,P,23

90000,P,0];
left join 
load sum(VALUE) as SUM90000 resident TABLE1 where TYPE='E';

OUTPUT:
noconcatenate

load CODE, if(CODE='90000',SUM90000,VALUE) as VALUE, TYPE resident TABLE1;

drop table TABLE1;

 

output:

Taoufiq_Zarra_0-1612174625490.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Carlaf_93
Creator II
Creator II
Author

Thanks. I have also a year field... how shoul i insert it?

Taoufiq_Zarra

@Carlaf_93  just add it after comma .

TABLE1:

LOAD * INLINE [

CODE, TYPE, VALUE,OTHERFIELD

1,E,10,other

2,P,23,other

90000,P,0,other];
left join 
load sum(VALUE) as SUM90000 resident TABLE1 where TYPE='E';

OUTPUT:
noconcatenate

load CODE, if(CODE='90000',SUM90000,VALUE) as VALUE, TYPE,OTHERFIELD resident TABLE1;

drop table TABLE1;

 

output:

Taoufiq_Zarra_0-1612175449352.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Carlaf_93
Creator II
Creator II
Author

Something isn't correct... it gives me the double of the value of all the years...

 

so code 90000 of year 2020 = 2000000

code 90000 of year 2019 = 2000000

code 90000 of year 2018 = 2000000