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: 
Peony
Creator III
Creator III

How to group field values

Hi all.

Could you please help me to solve next task. 
I'm loading field and I need to group values this field have. 
What I'm loading looks like this:
FieldName
Item1
Item2
Item3
Item4
Item5
Item6
Item7
Item8
Item9
Item10

I need to combine items in the field into a group of 4 pieces. If there are less than 4 items, then combine as many as there are. So result expected to be like this

FieldName, FieldGroup
Item1, Group1
Item2, Group1
Item3, Group1
Item4, Group1
Item5, Group2
Item6, Group2
Item7, Group2
Item8, Group2
Item9, Group3
Item10, Group3

I can't just bring groups manually because there will new item with each data refresh, so grouping process should be automatized somehow. I will be thankful for any hint hot this could be done. 

Labels (3)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You could do something like this:

Data:
Load * Inline [

FieldName
Item1
Item2
Item3
Item4
Item5
Item6
Item7
Item8
Item9
Item10
];

Groups:
LOAD
  FieldName,
  'Group' & (
Mod(FieldIndex('FieldName', FieldName),4)+1) as Group
Resident Data;

Change the "4" if you want a different number of groups.

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com 

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You could do something like this:

Data:
Load * Inline [

FieldName
Item1
Item2
Item3
Item4
Item5
Item6
Item7
Item8
Item9
Item10
];

Groups:
LOAD
  FieldName,
  'Group' & (
Mod(FieldIndex('FieldName', FieldName),4)+1) as Group
Resident Data;

Change the "4" if you want a different number of groups.

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com 

Peony
Creator III
Creator III
Author

@rwunderlich Thank you! This is exactly what I need!