Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Do do I rangesum with multiple dimensions?

I have a dataset containing Year, Age, and Loss.

For example:

YearAgeLoss
2007250
20073100
2009625
20071260
20081570
20091645
20101865

And I want to create a line chart with Age on the x-axis and cumulative loss amount on the y-axis, and a separate line for each year.

So for 2007, age 1 would be 0, age 2 would be 50, age 3 would be 50 + 100 = 150, age 4 would be 150, ... age 12 would be 210, etc.

I created a line chart with Age as the first dimension and Year as the second.  The expression is

RangeSum (above(sum(Loss),0,RowNo()))

But this doesn't result in the right figures.  If I switch the chart to a table, the table looks like this:

AgeYearLoss
2200750
32007150
62009175
122007235
152008305

So I thought maybe it had something to do with sorting, so I sorted the data in my data model by year and then by age but this didn't fix the problem. 

What would the correct expression be for this?

Thanks!

14 Replies
Not applicable
Author

Sure, here it is.

sunny_talwar

May be try like this:

Table:

LOAD Year*100+Age as Sort1,

  Year as Year1,

    Age as Age1,

    Loss

FROM

[data.xlsx]

(ooxml, embedded labels);

FinalTable:

LOAD Year1 as Year,

  Age1 as Age,

  Loss,

  Sort1 as Sort,

  AutoNumber(Age1, Year1) as Key

Resident Table

Order By Sort1;

DROP Table Table;

The chart below should work the way you would expect.

Not applicable
Author

I feel like we're getting close.  This certainly works for the dataset I provided but it does not work when I apply this logic to my real dataset.

In the dataset I provided, a subset of the data model looks like this:

   

AgeYearKeySortLoss
12200712007122
19200722007192499999
2620073200726-2000000
5120074200751265000
5220075200752370000
53200762007538500
54200772007540
5520078200755-45286.6
562007920075612488.82
61200710200761

468

   

In my actual data, the same subset of data would look like this:

   

AgeYearKeySortLoss
122007122007122
192007192007192499999
26200726200726-2000000
51200751200751265000
52200752200752370000
532007532007538500
542007542007540
55200755200755-45286.6
5620075620075612488.82
61200761200761468

As you can see, all columns are identical except for 'Key'.  The keys are difference because I have millions of records in my actual data, so I have a record for almost every year/age combination and therefore 2007 age 12 results in a key of 12 rather than 1.  I attached a QVW and data file showing what this ends up looking like in qlik.

sunny_talwar

I think this should work out for you.

Script:

Table:

LOAD Year as Year1,

    Age,

    Loss

FROM

[data.xlsx]

(ooxml, embedded labels);

FinalTable:

LOAD Loss,

  Year1 as Year,

  Age,

  AutoNumber(Age, Year1) as Key

Resident Table

Order By Year1, Age;

DROP Table Table;

Not applicable
Author

That worked, thanks!