Skip to main content
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!

1 Solution

Accepted Solutions
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;

View solution in original post

14 Replies
sunny_talwar

Try this:

RangeSum(Above(TOTAL Sum(Loss), 0, RowNo(TOTAL)))

Not applicable
Author

Sunny,

Thank you for the response but this doesn't quite work either. It look like this results in a cumulative loss for all years combined. 

sunny_talwar

Is there a sample you can provide (may be a qvw where you have been working on) so that we can also play around with it a little

Not applicable
Author

Sure, here you go:

sunny_talwar

Not sure if you have QV12 or not, but I can probably help you with a script solution for QV11.2 or before if you can confirm that one of these is what you are looking for.

Capture.PNG

Not applicable
Author

I have QV 11.2

That second chart looks right.  The values for 2008 don't look right in the first chart.

sunny_talwar

So here is what you need to do. On there first occurrence, sort by Year field first followed by age field. and then you can use this expression:

Aggr(RangeSum(Above(Sum(Loss), 0, RowNo())), Year, Age)

Not applicable
Author

I'm not quite sure I understand what you mean when you say "On there first occurrence, sort by Year field first followed by age field."  I went into chart properties and selected 'Sort' but I don't see an option to sort Year first and Age second.

If instead I change the chart to a straight table then it allows me to sort by Year and then Age.

Here's what it looks like when I have the chart set to a line chart:

And then here's a straight table:

sunny_talwar

This will be needed to be done in the script. Would you be able to provide this Excel file so that I can reload your qvw file?

C:\Users\A104028\Desktop\New Claims Tracking\CAD\Formula Test\data.xlsx