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

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Ovelaping Buckets


I would like to write a case statement for overlaping puckers

for ex: I have account ids 1,2,3,4,5 with the balance 25,50,75,80,100

Buckets for more than balance of 25. It means everything will fall in this bucket

Buckets for more than 50  ( 2,3,4,5 will fall in this bucket)

Buckets for more than 80

Normal if wont work since we have overlaping buckets. I would like display the data and calculations based on these buckets.

Help will be greatly appriciated.

Thanks,

Abhi

Labels (1)
3 Replies
Not applicable
Author

You can handle this at script level as front end level

IF(balance<=25,'Bucket 25',IF(balance<=80,'Bucket under 80','Bucket over 80')) as bucket;

Not applicable
Author

I have tried this, it wont work, since conflicting data is under 2 buckets, for ex: I have some id's whih has balance of > 25 come in '> 25 and' > 50 buckets, for ex: 80 will should come under both buckets, case statement by if does not work.

Carlos_Reyes
Partner - Specialist
Partner - Specialist

You'll have to multiply the number of records by the number of buckets so that if an account falls in N buckets you'll have N records for that account. For instance, I'd do the next:

// Load your Accounts table and join the distinct Bucket values to create all the possible combinations

ACCOUNTS_TEMP:

LOAD

     ACCOUNT_ID,

     BALANCE

FROM TABLE1;

JOIN

LOAD * INLINE [

BUCKETS

25

50

80

];

// Create a flag in order to know whether an account falls in a bucket and filter unfulfilling records

ACCOUNTS:

LOAD

     ACCOUNT_ID,

     BALANCE,

     ' > ' & FALLS_IN_BUCKET      AS   BUCKET

WHERE NOT ISNULL(FALLS_IN_BUCKET );

LOAD

     ACCOUNT_ID,

     BALANCE,

     IF(BALANCE >= BUCKETS, BUCKETS, NULL()) AS FALLS_IN_BUCKET

RESIDENT ACCOUNTS_TEMP;

DROP TABLE ACCOUNTS_TEMP;