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: 
oscargm_bi
Contributor III
Contributor III

Clasify numbers in a column into a range

Hi all,

 

I need help of you guys... I have a column with many numbers, i need to clasify them in some range in a new column, like 1 to 100, 101 to 300, 300 to 500, 501 to 1000. How can i do that in the script?

 

Thanks

1 Solution

Accepted Solutions
johngouws
Partner - Specialist
Partner - Specialist

Hi. Try something like this: 

t1:
LOAD
*,
if(Number <= 100, '0 to 100',
if(Number > 100 and Number <= 200 , '101 to 200',
if(Number > 200 and Number <= 300 , '201 to 300',
if(Number > 300 and Number <= 400 , '301 to 400',
if(Number > 400 and Number <= 500 , '401 to 500',
if(Number > 500 and Number <= 600 , '501 to 600',
if(Number > 600 , '> 600'
))))))) as [Number Group]
;
LOAD * INLINE [
Number
21
35
101
100
150
10
180
220
280
302
399
400
401
450
499
500
550
560
600
601
];
exit script;

It will produce this: Sort the 'Number Group' by Load order: 

Capture.JPG

 

View solution in original post

4 Replies
johngouws
Partner - Specialist
Partner - Specialist

Hi. Try something like this: 

t1:
LOAD
*,
if(Number <= 100, '0 to 100',
if(Number > 100 and Number <= 200 , '101 to 200',
if(Number > 200 and Number <= 300 , '201 to 300',
if(Number > 300 and Number <= 400 , '301 to 400',
if(Number > 400 and Number <= 500 , '401 to 500',
if(Number > 500 and Number <= 600 , '501 to 600',
if(Number > 600 , '> 600'
))))))) as [Number Group]
;
LOAD * INLINE [
Number
21
35
101
100
150
10
180
220
280
302
399
400
401
450
499
500
550
560
600
601
];
exit script;

It will produce this: Sort the 'Number Group' by Load order: 

Capture.JPG

 

Vegar
MVP
MVP

You can also use IntervalMatch to solve this.

Transactions:

Load 

[The Number column],

[Other columns]

From [Your Source];

 

[Class table]:

Load * inline [

A, B, Class

1,100, '1-100'

101, 300, '101-300'

301, 500, '301-500'

501, 1000, '501-1000'

1001, 10000000, '>1001'

];

Intervalmatch :

Intervalmatch ([The Number column])

Load A, B

Resident [Class table];

Channa
Specialist III
Specialist III

if the range is constant you can use Class() function

Channa
oscargm_bi
Contributor III
Contributor III
Author

Thank you, this solution was exactly what I wanted.

 

Regards.