Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
francofiorillo
Partner - Creator
Partner - Creator

How to calculate the frequency of a field in the script?

Hello.

I have the following date table. TAB1

     

ABCDE
17/11/201717/11/201720/11/201721/11/201722/11/2017
16/11/201718/11/201720/11/201722/11/201723/11/2017
20/11/201721/11/201722/11/201723/11/201724/11/2017
22/11/201723/11/201724/12/201727/12/201728/12/2017
24/11/201727/11/201728/11/201729/11/201730/11/2017
20/11/201720/11/201721/11/201722/11/201723/11/2017
28/11/201729/11/201730/11/201701/12/201704/12/2017
21/11/201722/11/201723/11/201724/11/201725/11/2017
22/11/201723/11/201724/11/201727/11/201728/11/2017
23/11/201724/11/201727/11/201728/11/201729/11/2017

I want to build a TAB2 table in the script, in which, next to each value of a column, I have to calculate the number of times that value appears in the column.

For example, in the following tab, I entered the columns F and G of the frequencies relative to columns A and B of Tab1.

   

AFBGCDE
17/11/2017117/11/2017120/11/201721/11/201722/11/2017
16/11/2017118/11/2017120/11/201722/11/201723/11/2017
20/11/2017221/11/2017122/11/201723/11/201724/11/2017
22/11/2017223/11/2017224/12/201727/12/201728/12/2017
24/11/2017127/11/2017128/11/201729/11/201730/11/2017
20/11/2017220/11/2017121/11/201722/11/201723/11/2017
28/11/2017129/11/2017130/11/201701/12/201704/12/2017
21/11/2017122/11/2017123/11/201724/11/201725/11/2017
22/11/2017223/11/2017224/11/201727/11/201728/11/2017
23/11/2017124/11/2017127/11/201728/11/201729/11/2017

can you please help me?

thank you

1 Solution

Accepted Solutions
MarcoWedel

Hi,

nice to hear that it works for you.

Please close your thread if your question is answered.

Thanks

Regards

Marco

View solution in original post

6 Replies
rubenmarin

Hi Francesco, you use mapping tables with the gouped value for each date and use applymap to assign value:

mapA:

Mapping LOAD A

     Count(A)

resident table group by A;

// same for B

FinalTable:

LOAD A,

ApplyMap('mapA', A) as F,

B,

ApplyMap('mapB', B) as G,

..

petter
Partner - Champion III
Partner - Champion III

This is an approach that works with LEFT JOIN and GROUP BY:

FOR EACH Fld IN 'A','B','C','D','E'

    LEFT JOIN

    LOAD

      $(Fld),

      Count($(Fld))

    RESIDENT

      Tab1

    GROUP BY $(Fld);

NEXT

MarcoWedel

Hi,

another solution might be:

QlikCommunity_Thread_282187_Pic1.JPG

TAB1:

LOAD RecNo() as ID, * FROM [https://community.qlik.com/thread/282187] (html, codepage is 1252, embedded labels, table is @1);

tabTemp:

CrossTable (FieldNam, FieldVal)

LOAD * Resident TAB1;

Join

LOAD FieldNam,

    FieldVal,

    Count(FieldVal) as FieldValFreq

Resident tabTemp

Group By FieldNam, FieldVal;

TAB2:

Generic

LOAD ID,

    FieldNam&'Freq',

    FieldValFreq

Resident tabTemp;

DROP Table tabTemp;

hope this helps

regards

Marco

MarcoWedel

or similar to Petter's solution:

QlikCommunity_Thread_282187_Pic2.JPG

SET vTabNam = 'TAB1';

$(vTabNam):

LOAD * FROM [https://community.qlik.com/thread/282187] (html, codepage is 1252, embedded labels, table is @1);

FOR vFldNum = 1 to NoOfFields('$(vTabNam)')

    vFldNam = FieldName(vFldNum,'$(vTabNam)');

    Left Join ($(vTabNam))

    LOAD $(vFldNam),

         Count($(vFldNam)) as $(vFldNam)Freq

    Resident $(vTabNam)

    Group By $(vFldNam);

NEXT

hope this helps

regards

Marco

francofiorillo
Partner - Creator
Partner - Creator
Author

HI Marco.

perfect !

works great !

many thanks to Marco.

I will also try the other suggestions that seem logically correct.

thank you all.

Hello

MarcoWedel

Hi,

nice to hear that it works for you.

Please close your thread if your question is answered.

Thanks

Regards

Marco