Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
andrespa
Specialist
Specialist

Accumulated count in script

Hi All, I need to do something it may be simple but so far I'm no able to get it. So basically what I want is illustrated in the "AccumulatedCount" column below:

KeyStartDateEndDateCountAccumulatedCount
110/02/201812/02/201811
311/02/201813/02/201812
412/02/201814/02/201813
513/02/201815/02/201814
514/02/201816/02/201815

The closest shoot I got so far is use this expression:

if(StartDate< Previous(EndDate), Count+1, Previous(Count))           AS  AccumulatedCount


But, of course that's not what I want cause I'm summing 1 to 1 all the time:


KeyStartDateEndDateCountAccumulatedCount
110/02/201812/02/201811
311/02/201813/02/201812
412/02/201814/02/201812
513/02/201815/02/201812
514/02/201816/02/201812

So I need something like that expression but over the AccumulatedCount field but not sure how to do it. Hope it makes sense.

Cheers,

Andrés

1 Solution

Accepted Solutions
sunny_talwar

You might have more than one dimensions in there.... Try this

RangeSum(Above(TOTAL SessionCount, 0, RowNo(TOTAL)))

View solution in original post

14 Replies
sunny_talwar

Try this

RangeSum(Peek('AccumulatedCount'), 1) as AccumulatedCount

andrespa
Specialist
Specialist
Author

It doesn't work. The problem really is that you need to add 1 every single time the conditions fulfills (i.e. a simple a++ in any programming language) but here in the load editor you can't just do that. So I'm not sure if this is doable or you need to do it in the chart instead (although the same problem might happen there).

Not sure how to solve it.

sunny_talwar

You can, try this

If(StartDate < Previous(EndDate), RangeSum(Peek('AccumulatedCount'), 1), Peek('AccumulatedCount')) as AccumulatedCount

andrespa
Specialist
Specialist
Author

That's exactly what I tried before. But something weird is happening or I'm missing something cause even in a table chart using the below expression and simplifying it without taking into account the date fields:

RangeSum(Above(SessionCount,0))

RangeSum.PNG

Which should work to gave me and accumulated value, it's just displaying always 1.

The same thing happens in the script if I use peek.

sunny_talwar

Not really, you have not used RowNo()

RangeSum(Above(SessionCount, 0, RowNo()))

andrespa
Specialist
Specialist
Author

Indeed, you're right but still not working:

RangeSum.PNG

sunny_talwar

You might have more than one dimensions in there.... Try this

RangeSum(Above(TOTAL SessionCount, 0, RowNo(TOTAL)))

andrespa
Specialist
Specialist
Author

Perfect! Didn't know you need to do that when you have more than 1 dimension. Thanks a lot, you've been very helpful!

Cheers,

Andrés

sunny_talwar

But this will continue to accumulate regardless of change in any of your dimensions.... if that is what you want, then that is great... else you will have to play around with your expression to make it to work