Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
joeallen
Contributor III
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?

Labels (1)
15 Replies
sunny_talwar

Yes, some sort of if statement would be needed to get this to work.

tresesco
MVP
MVP

Sunny,

I tried expression:  =Avg(F3)& Count(GetCurrentField([Group]))

and it works, I guess it's about scope where/when you are using this. Today I have to log off early, but definitely will come back and do some more testing..

joeallen
Contributor III
Contributor III
Author

So simply an If statement when GetCurrentField is Date or YearWeek, then have the expression as YearMonth grouping, and if GetCurrentField is YearMonth, have Year as grouping in the expression, for example?
sunny_talwar

I don't think that this is working as you might be expecting. =Avg(F3)& Count(GetCurrentField([Group])). All it is doing is to Counting the text... not the field itself.... Try this =Avg(F3)& Concat(DISTINCT GetCurrentField([Group])) and you will see F2 instead of AA and BB when you are on F2 within your group.

sunny_talwar

I think so, exact expression will have to tested out but you can have an overarching if statement or you can have an if statement just for your dimensions part.... but your idea is right

tresesco
MVP
MVP

Spot on Sunny. Thanks.