Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a question regarding cumulative sum of the data. I want to realize the following function:
original table:
| a |
|---|
| 1 |
| 1 |
| 1 |
Output table:
| a | obs | Cum |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 1 | |
| 1 | 3 | 2 |
| 1 | 4 | 3 |
| 5 | 3 |
Anyone can help?
Thanks!
can you post some sample data please. Not sure how the dimension is segregated when it has just 1 unique value.
try this in expression side
for obs fieldname write rowno()
rangesum(above(sum(Fieldname),0,rowno()))
You could also try this (assuming that your original table has some sort of 'key' field), it will allow you to make a selection and still see the cumulative value.
sum(aggr(rangesum(above(total sum({<key=>} a),0,RowNo())),key))
I recommend this tutorial:
Calculating rolling n-period totals, averages or other aggregations
http://community.qlik.com/docs/DOC-4252
Cheers,
Paul
Please check enclosed file..
can you post the code cause i am not able to access that qvw file.
Thank you
Script..
Load * Inline
[
ID,a
1, 1
2,
3, 1
4, 1
5,
];
Create a straight table
Dimension = ID
Expression
1) RowNo()
2) RangeSum(Above(Sum(a),0,RowNo()))
How can I write this all in the script? I was trying to write them in the script but it doesn't recognize the "Above" function...
Cumulative_sum:
Load * Inline
[
ID,a
1, 1
2,
3, 1
4, 1
5,
];
table:
load
RowNo() as Sequence1,
RangeSum(a, Peek('CumSum')) AS CumSum,
*
Resident Cumulative_sum
order by ID, a;
You need to create a straight table...!!!
Script..
Load * Inline
[
ID,a
1, 1
2,
3, 1
4, 1
5,
];
Create a straight table
Dimension = ID
Expression
1) RowNo()
2) RangeSum(Above(Sum(a),0,RowNo()))