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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Replace null value with expression output

My Scenario is

Group      Amount

                   

  A             100

  B             200

  C             

   D              400

   E            

convert to

Group   Amount

A           100

B             200

C             300 i.e (B+A)

D              400

E                500  i.e (D+A) 

there can be more null values like E and C .

New sum (Amount ) is calculated after replacing null with values.

4 Replies
alexandros17
Partner - Champion III
Partner - Champion III

Try something like:

If(isnull(myField), Sum(previous(myField), myField)

maxgro
MVP
MVP

SCRIPT

Source:

load * inline [

Group,    Amount      

A,        100

B,        200

C,         

D,        400

E,           

];

  

Final:

NoConcatenate load

Group,

// when Amount is null sum previuos Amount and Amount of first row (A)

if(len(trim(Amount))=0, peek(Amount) + peek(Amount, 0), Amount) as Amount

Resident Source

order by Group;

drop Table Source;

RESULT

GroupAmount
A100
B200
C300
D400
E500
Not applicable
Author

Thanks For Reply.

But One more concern is that we are taking value by specifying index to peek() but I want the value to peek

by matching the group and logic to fill different null values are different.

Can i achieve this in front end using IF or may be by Set Analysis.

maxgro
MVP
MVP

if  the logic is different for every Group with missing Amount  you may try in a chart ordered by Group with

DIMENSION Group

EXPRESSION

if(Group='C', concat(total aggr(if(Group='A', sum(Amount)), Group), '-', Group) + above(sum(Amount)),

if(Group='E', concat(total aggr(if(Group='A', sum(Amount)), Group), '-', Group) + above(sum(Amount)),

sum(Amount) ))