Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

joeallen
New Contributor III

Cumulative sum expression that works with cyclic group?

Hello

Say I have sum(Sales)

I want it as a cumulative sum over a time period, to start with Date

So say sum sales for 20191001 is 200, for 20191002 is 300, then it should show 200+300 as the value on 20191002 etc...

Then you can for example use the new for QV12 sortable AGGR function

Aggr(RangeSum(Above(sum(Sales), 0, RowNo())), YearMonth, (Date, (NUMERIC)))

This works for me.

HOWEVER

My time period is really not only Date, but it's a cyclic group with Date, YearWeek, YearMonth and Year

The above expression only works for Date, but not for the others

How do I make an expression with cumulative sum that works for this cyclic time group?

1 Solution

Accepted Solutions

Re: Cumulative sum expression that works with cyclic group?

Correct me if I am wrong @tresesco , but won't we need Dollar sign expansion here?

Aggr(
  RangeSum(Above(Sum(Sales), 0, RowNo()))
, YearMonth, ($(='[' & GetCurrentField (group_name) & ']'), (NUMERIC)))

View solution in original post

15 Replies
MVP
MVP

Re: Cumulative sum expression that works with cyclic group?

Try replacing your direct field in aggr sort argument by expression: GetCurrentField (group_name), like:

 

Aggr(RangeSum(Above(sum(Sales), 0, RowNo())), YearMonth, (GetCurrentField (group_name), (NUMERIC)))

 

 

Re: Cumulative sum expression that works with cyclic group?

Correct me if I am wrong @tresesco , but won't we need Dollar sign expansion here?

Aggr(
  RangeSum(Above(Sum(Sales), 0, RowNo()))
, YearMonth, ($(='[' & GetCurrentField (group_name) & ']'), (NUMERIC)))

View solution in original post

MVP
MVP

Re: Cumulative sum expression that works with cyclic group?

Sunny,

That is something I wanted to test and post. In fact I typed two possibilities as answer, one with $ and another without, then I thought that, since the getcurrentfield() would actually be evaluated with the chart (since it is dimension-selection sensitive) - the main expression and getcurrentfield() evaluation might work simultaneously. Again, not tested here.    

Re: Cumulative sum expression that works with cyclic group?

From my understanding of using this in the past, GetCurrentField() will just give the name of the field as a text... to actually make it read as a field, you will need $()... but let me know if you find otherwise while testing.

MVP
MVP

Re: Cumulative sum expression that works with cyclic group?

If the field name doesn't contain space, that should probably not matter. So it's not about evaluating before the actual expression gets evaluated, rather adding '[' ']' to give a field name convention for those even that has spaces in field name.  

 

Edit: I roughly tested and it works (without space in field name obviously)

Re: Cumulative sum expression that works with cyclic group?

Spaces is taken care by '[' and ']', but to convert it to field is done by $(=)... I still feel it is needed.

MVP
MVP

Re: Cumulative sum expression that works with cyclic group?

Sunny, so yes, yours is a better approach since that would work in all scenarios. 🙂

Re: Cumulative sum expression that works with cyclic group?

For some reason I don't see it working without $().. please check the attached file

 

joeallen
New Contributor III

Re: Cumulative sum expression that works with cyclic group?

Thanks for the idea Tresesco and for the correction Sunny.

It works fine for Date and YearWeek (I want the cumulative sum to reset per YearMonth for Date and YearWeek so I want this expression as is for those two)

However once the Cyclic group changes to YearMonth it doesn't work any more (it just sums like normal and not cumulative per YearMonth, I assume because of the YearMonth grouping in the expression that works so well for YearWeek and Date. And Year doesn't work at all.
I guess have to use some kind of If function here to get YearMonth and Year to work?