Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
steve_br
Creator
Creator

Creating range

Hello!

I would like to create a line chart using the sample data beneath. I need to aggregate the kilograms into three groups: 0-3000, 3001-6000, 6001-9000 so that the chart shows the following information:

y-axis: costs per ton

x-axis: month

lines: cost development for each group

legend: carriers

I don't know how to create these three groups using the given ranges. Would appreciate any help. Thanks!

CarrierKGCostDate
Carrier 138361421-03-16
Carrier 115901520-02-16
Carrier 124031606-01-16
Carrier 18341916-03-16
Carrier 17231526-03-16
Carrier 156101425-03-16
Carrier 154561430-01-16
Carrier 18286605-01-16
Carrier 115691919-02-16
Carrier 16925615-02-16
Carrier 120111511-01-16
Carrier 16545719-03-16
Carrier 119941719-01-16
Carrier 137961515-01-16
Carrier 125811618-03-16
Carrier 117471815-02-16
Carrier 159761122-01-16
Carrier 155451511-01-16
Carrier 120742026-03-16
Carrier 18685931-03-16
Carrier 187941002-03-16
Carrier 116041717-01-16
Carrier 16661525-02-16
Carrier 16846720-01-16
Carrier 135401312-03-16
Carrier 142061218-02-16
Carrier 133601407-01-16
Carrier 115901928-03-16
Carrier 138851022-02-16
Carrier 126911606-02-16
Carrier 256881218-01-16
Carrier 210221915-03-16
Carrier 26651525-03-16
Carrier 220231915-02-16
Carrier 230851425-01-16
Carrier 250431304-01-16
Carrier 231251031-03-16
Carrier 241091321-01-16
Carrier 258441511-02-16
Carrier 240641030-01-16
Carrier 222911708-02-16
Carrier 27829601-02-16
Carrier 26804701-02-16
Carrier 235401424-03-16
Carrier 28161809-01-16
Carrier 26486610-01-16
Carrier 253481126-03-16
Carrier 28914707-03-16
Carrier 248631215-03-16
Carrier 242271006-02-16
Carrier 221141605-02-16
Carrier 250281430-03-16
Carrier 231731117-03-16
Carrier 223821609-03-16
Carrier 210212005-01-16
Carrier 26096501-03-16
Carrier 28820928-01-16
Carrier 258161207-02-16
Carrier 237371026-02-16
Carrier 28369626-01-16
1 Solution

Accepted Solutions
oknotsen
Master III
Master III

I suggest you look into using the intervalmatch() function.

http://help.qlik.com/en-US/sense/2.2/Subsystems/Hub/Content/Scripting/ScriptPrefixes/IntervalMatch.h...

With this function you can setup your own ranges, which can even overlap if that would be of use for you.

Not behind my work PC, so no access to the examples I have there. If you would like some, let me know and I will post those tomorrow.

May you live in interesting times!

View solution in original post

6 Replies
Gysbert_Wassenaar

Here's one way:

LOAD

     Carrier,

     KG,

     Class(KG, 3000) as KG_Range

     Cost,

     Date

FROM

     ...source...

     ;


talk is cheap, supply exceeds demand
steve_br
Creator
Creator
Author

Thank you, but I would prefer to create a new dimension with a specific expression and I don't wanna use the class function, because I also work on other cases where I need different grouping such as 0-1000, 1000-4000, 4000-9000. Would this be possible?

oknotsen
Master III
Master III

I suggest you look into using the intervalmatch() function.

http://help.qlik.com/en-US/sense/2.2/Subsystems/Hub/Content/Scripting/ScriptPrefixes/IntervalMatch.h...

With this function you can setup your own ranges, which can even overlap if that would be of use for you.

Not behind my work PC, so no access to the examples I have there. If you would like some, let me know and I will post those tomorrow.

May you live in interesting times!
steve_br
Creator
Creator
Author

Thank you for the suggestion! I will have a look at it.

Actually I just did something else and it seems to work:

Aggr(If(KG<3000, '<3t',

If(KG>=3000 and KG<6000, '3-6t',

If(KG>=6000 and KG<9000, '6-9t',

'9+'))),KG)

Is this also a correct solution?

jonathandienst
Partner - Champion III
Partner - Champion III

The calculated dimension will work, but you will get better performance* and easier maintenance if you perform an interval match in the load script.

* If your model is small (<1m rows), then the performance of the calculated dimension would probably be acceptable. If the model is large (>10m rows), then the performance will matter.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
steve_br
Creator
Creator
Author

Okay, great. Thank you all for the help!