Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Data fields with multiple entries

Hi All,

I have a problem with some survey data which I'm not sure how to process before I load it into Qlikview.

My data is downloaded from the back end of an online survey where we allow multiple answers to be selected for some of the questions.

The data ends up similarly to the example below (see favourite colours):

NameFavourite ColoursFavourite shape
JamesBlue, Red, Greencircle
PeterRed, Yellow, Whiterectangle
HenryBlue, White, Orangetriangle
GeorgeGreen, Blue, Redrectangle
FredWhite, Yellowrectangle
SteveRedtriangle
JordanBlue, Greencircle

I'm not sure what the best way to process this data is.

I've heard that a good option might be to do the following... but with several questions allowing multiple answers the final database might end up huge!

NameFavourite ColoursFavourite shape
JamesBluecircle
JamesRedcircle
JamesGreencircle
PeterRedrectangle
PeterYellowrectangle
PeterWhiterectangle
HenryBluetriangle

Although this might work in principle... i can still see there being issues when finished, ie any 'count' field would be out...

Also, the survey doesnt specify that they NEED to select 3 answers, only that they can select upto... so I'd end up with different numbers of lines for each entry...

Any help would be really appreciated - I'm pretty stumped with this one.

Andrew

1 Solution

Accepted Solutions
rustyfishbones
Honored Contributor II

Re: Data fields with multiple entries

Try using SUBFIELD Function in the Script

So it would be

SUBFIELD([Favourite Colours],',') AS [Favourite Colours]

Regards

Al

13 Replies
Not applicable

Re: Data fields with multiple entries

If your concern is regarding the Count function, then you can always use "Count(Distnct 'field')" for getting unique record count.

Vegar
Valued Contributor

Re: Data fields with multiple entries

I would have split your preferences on one table for each question. In this case. One ShapePreference dimension (If it is possible that a person may have more than one favorite shape) and one ColorPreference dimension.

With this solution you may calculate how many colors each person prefer. how many persons prefere a color etc.

I provide a qvw-example.

Please ekskuse my Norglish and Swenglish typos.
rajeshvaswani77
Valued Contributor III

Re: Data fields with multiple entries

subfield function could be a part of the solution. To be true I am not sure what the full solution will be. I am curious to know the solution.

thanks,

Rajesh Vaswani

rustyfishbones
Honored Contributor II

Re: Data fields with multiple entries

Try using SUBFIELD Function in the Script

So it would be

SUBFIELD([Favourite Colours],',') AS [Favourite Colours]

Regards

Al

Vegar
Valued Contributor

Re: Data fields with multiple entries

I used the subfield-function in my example.

Please ekskuse my Norglish and Swenglish typos.
Not applicable

Re: Data fields with multiple entries

Hi Alan, I think I like the way you're going here.

Sorry to be a complete novice, but could you give a brief overview of how the function works?

Kind regards,

Andrew

Not applicable

Re: Data fields with multiple entries

Thanks for taking the time to do this, really useful, great solution thanks very much!

Not applicable

Re: Data fields with multiple entries

Further to the note I just added, I've just taken a look at the Subfunction field and I'm not sure how I could alter it to suit the data, but you might know a way?

My understanding is that if I used the subfuntion field, I would effectively split out the favourite colours into 3 columns, the problem would then be bringing them all back together so that I could then filter for example 'blue' and show all respondents with blue listed (whether they put it first, second or third)

Not sure if anyone can help here?

Many thanks,

Andrew

Re: Re: Data fields with multiple entries

If you use the subfield function with only two parameters, i.e. fieldname and separator, then a new record will be created for every value in the list. That also means that it doesn't get confused if there are two, four or ten (comma) separated values. Every value in the list will end up in its own record but in the same column. Just like the result table example you posted.

SurveyData:

Load

    Name,

    subfield([Favourite Colours],',') as [Favourite Colours],

    [Favourite shape]

From ...mysource...;

Also your qlikview document will not explode in size (unless you have exceptionally large number of records to begin with). See this blog post for an explanation:Symbol Tables and Bit-Stuffed Pointers


talk is cheap, supply exceeds demand
Community Browser