Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Grouping a range in an IF statement


Is there a way to group a range within an IF statement without having to list each item on its own line? I have commodity codes in a range of 5201 thru 5251 and I need to group them into T-SLEEVES. I know I can do this individually but I would rather do this in less than 50 lines if possible. Please advise.

12 Replies
ecolomer
Master II
Master II

The codes are numeric and are at equal intervals?

Not applicable
Author

Here is a sample of so code that already works:

If(WildMatch([CommodityCode], '*5002*'), 'D-SLEEVES',

If(WildMatch([CommodityCode], '*5004*'), 'D-SLEEVES',

If(WildMatch([CommodityCode], '*5005*'), 'D-SLEEVES',

If(WildMatch([CommodityCode], '*5006*'), 'D-SLEEVES',

If(WildMatch([CommodityCode], '*5007*'), 'D-SLEEVES', etc...

  So since I need to use single quotes around the commodity code '5002', does that mean there are text and not numeric?

Not applicable
Author

I think QV would treat them as numeric.

Can you use a wildcard character around '50**' for different intervals?

Not applicable
Author

I can use wildcard characters but I am not sure what you mean for different intervals. I do not want to type 50 lines of "IF" statement to assign this group to T-SLEEVES (see example above). Since these values are concurrent (one after another), is there a way I can do this assignment, in the script, in less lines?

Not applicable
Author

Maybe like

If(WildMatch([CommodityCode], '500*'), 'D-SLEEVES',

f(WildMatch([CommodityCode], '501*'), 'D-SLEEVES',

If(WildMatch([CommodityCode], '502*'), 'D-SLEEVES',

If(WildMatch([CommodityCode], '503*'), 'D-SLEEVES',

If(WildMatch([CommodityCode], '504*'), 'D-SLEEVES',

and so on.  Maybe not the most elegant solution but saves you a lot of lines.

anbu1984
Master III
Master III

=If([CommodityCode]>= 5201 And [CommodityCode] <= 5251, 'T-SLEEVES')

Not applicable
Author

Or use a list of codes and sleeves (INLINE or an Excel sheet) in combination with ApplyMap

Code_Sleeves:

MAPPING INLINE [

CommunityCodeShort, Sleeves

5002, D-SLEEVES

5004, D-SLEEVES

5005, D-SLEEVES

5006, D-SLEEVES

5007, D-SLEEVES

];

ApplyMap('Code_Sleeves',Left([CommunityCode],4),'Nothing Found')

Or something like that

Not applicable
Author

I will give this a try.

Thank You!

Not applicable
Author

This would not work because it will bring in commodities that are NOT in the same group.

Thanks you.