Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Mahamed_Qlik
Specialist
Specialist

If is not working while creating value bucket as dimension in qliksense

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

Labels (1)
3 Replies
rubenmarin

Hi, there must be something else here, can you upload a sample to check? Maybe the '22' is 2 '11' values added.

vchuprina
Specialist
Specialist

Hi,

Could you please share the original data source?

I've tried to reproduce your issue, but in my case, everything works fine

vchuprina_1-1650101935566.png

 

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

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").
Vegar
MVP
MVP

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'.