Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Dear all,,
I am trying to create value bucket using if condition but only for one the values the bucket is showing wrong records.
Example:
1 to < 10 --- 'Category A'
10 to <20 --- 'Category B'
20 to <30 -- 'Category C'
30 to 40 -- ''Category D'
So I have written below script :
if( Value = 1 and Value <10 , 'Category A',
if( Value >=10 and Value <20, 'Category B'.
if( Value >=20 and Value <30, 'Category C',,'D')));
Expected output :
Value Category
2 Category A
12 Category B
22 Category C
33 Category D
But I m getting
Value Category
2 Category A
12 Category B
22 Category B
21 Category C
23 Category C
33 Category D
this is happing only for only one value from Category C that is 22 showing under Category B for rest it is showing correct.
Kindly help
Hi, there must be something else here, can you upload a sample to check? Maybe the '22' is 2 '11' values added.
Hi,
Could you please share the original data source?
I've tried to reproduce your issue, but in my case, everything works fine
DATA:
LOAD
Value,
if( Value >= 1 and Value <10 , 'Category A',
if( Value >=10 and Value <20, 'Category B',
if( Value >=20 and Value <30, 'Category C','Category D'))) AS Bucket;
LOAD * Inline[
Value, Category
2, Category A
12, Category B
22, Category B
21, Category C
23, Category C
33, Category D
];
Regards,
Vitalii
Your logic looks fine, I would guess there is something with your values, try loading them as a NUM() .
PS: there is a syntax mistake in your expression. You have a punctuation mark, not comma, after 'Category B'.