Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
Try something like:
If(isnull(myField), Sum(previous(myField), myField)
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
Group | Amount |
A | 100 |
B | 200 |
C | 300 |
D | 400 |
E | 500 |
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.
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) ))