Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Ceb
Contributor III
Contributor III

Cummulative SUM with 2 dimensions

Hi,

I have a table with Date, Group, Count, Cumulative Count(data below)

DateGroupCountCummulative Count
01/01/1980A05115
09/01/1984B01364
01/01/1988A7469
02/04/1988A02724
04/01/1988A1392
06/01/1988A22903
05/01/1989A12972
07/15/1993A13046
08/01/1993A03580
11/01/1993A05328
11/30/1993B11423
12/08/1993A13774
12/13/1993A03728
12/15/1993A12926
12/31/1993A23682
01/01/1994A03368
01/10/1994A15107
02/02/1994A05315
02/08/1994A12935
02/08/1994B11293
03/29/1994B01307
04/10/1994B11955

 

For cummulative count I have tried the below code but I am getting some weird values

=aggr(Rangesum( above(
count (
[ID])
,0,RowNo())),Group,Date)

Referred: https://community.qlik.com/t5/New-to-Qlik-Sense/Rangesum-cumulative-with-2-dimensions/td-p/1285355

Though if I try without the grouping(aggr function) I get the right values. 

 

 

Thanks,

Labels (3)
1 Solution

Accepted Solutions
sunny_talwar

May be you need to sort the Date field? Try this

=Aggr(
    RangeSum(Above(
        Count([ID])
    , 0, RowNo()))
, Group, (Date, (NUMERIC)))

View solution in original post

10 Replies
StarinieriG
Partner - Specialist
Partner - Specialist

Hi,

have you tried to add sum before aggr?

sum(aggr(Rangesum( above(
count (
[ID])
,0,RowNo())),Group,Date))

 

sunny_talwar

May be you need to sort the Date field? Try this

=Aggr(
    RangeSum(Above(
        Count([ID])
    , 0, RowNo()))
, Group, (Date, (NUMERIC)))
Ceb
Contributor III
Contributor III
Author

Thanks alot Sunny.

 

This works. But if I duplicate dates or even if I convert it to Months I have duplicate records on the X-axis

clipboard_image_0.png

How should I counter that?

 

Ceb
Contributor III
Contributor III
Author

Thanks alot Sunny.

 

This works. But if I duplicate dates or even if I convert it to Months I have duplicate records on the X-axis

 

clipboard_image_1.png

 

How should I counter that?

sunny_talwar

Difficult to know without having to take a look at this

Ceb
Contributor III
Contributor III
Author

In terms of a table I am getting something like this

Aug-2019B1233
Aug-2019A5455
Aug-2019C2059
Aug-2019B1234
Aug-2019A5456
Aug-2019B1235
Aug-2019A5459
Aug-2019A5461
Aug-2019C2060
Aug-2019A5466
Aug-2019C2061
Aug-2019B1239
Aug-2019D594
Aug-2019A5471
Aug-2019C2063
Aug-2019B1241
Aug-2019A5472
Aug-2019B1243
Sep-2019A5473
Sep-2019A5474
Sep-2019B1244

 

whereas I need to get this

Aug-2019D594
Aug-2019C2063
Aug-2019A5472
Aug-2019B1243
Sep-2019A5474
Sep-2019B1244

 

Hope this helps.

 

I did try using Month only as a dimension, I got the results I need but when I do Month-Year using this code

date(Date#([Network Eff Date],'MM/DD/YYYY'),'MMM-YYYY'), it duplicates

 

Also is it something to do with Rangesum and the Aggregate function?

sunny_talwar

I would use this for MonthYear

Date(MonthStart(Date#([Network Eff Date], 'MM/DD/YYYY')), 'MMM-YYYY')

 

Ceb
Contributor III
Contributor III
Author

Thanks for the reply.

I tried putting 

Date(MonthStart(Date#([Network Eff Date], 'MM/DD/YYYY')), 'MMM-YYYY')

this in the dimension and in the measure

=Aggr(
RangeSum(Above(
Count([ID])
, 0, RowNo()))
, [Group], ([Network Eff Date], (NUMERIC)))

 

And I got this result

clipboard_image_0.png

The dimension looks good but the values messed up. The values of the group went blank .

sunny_talwar

I would create this in the script

Date(MonthStart(Date#([Network Eff Date], 'MM/DD/YYYY')), 'MMM-YYYY') as [Network Eff Month and Year]

and then use this

=Aggr(
RangeSum(Above(
Count([ID])
, 0, RowNo()))
, [Group], ([Network Eff Month and Year], (NUMERIC)))