Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

column name based on count

Hi guys

I need to build a report on the frequency of receiving services:

Data    

clientIDserviceNameserviceKey
1111A1
1111A2
1111A3
1111B4
1111B5
1116B6
1117A7
1118A8
1119A9
1119A10
1119A11
1119A12
1119D13
1119D14
1119D15
1126D16
1127D17
1128A18
1128A19
1128A20
1128A21

I need to count the number of times each client has received a service and to present it in the table below

Result:

   

oncetwice 3 times  4 and more
A2 12
B 1
D2 1

Thanks

1 Solution

Accepted Solutions
maksim_senin
Partner - Creator III
Partner - Creator III

Hi,

In general you should decide whether you want to calc. in on-the-fly or calc it in load script. A general idea fo load sript:

1. 1st you should load distinct client list with counted times say in a field Counter

2. then you need to get min and max no. of times

3. make a cycle for i = min to max in which join to your client list records with Counter = i and add a field (once, twice, etc) with necessary value

If you want to calc that in the runtime, you'll definitely need calc. dimension which is not a best choice in a large amount of data.

Best regards,

Maxim

View solution in original post

8 Replies
maksim_senin
Partner - Creator III
Partner - Creator III

Hi,

In general you should decide whether you want to calc. in on-the-fly or calc it in load script. A general idea fo load sript:

1. 1st you should load distinct client list with counted times say in a field Counter

2. then you need to get min and max no. of times

3. make a cycle for i = min to max in which join to your client list records with Counter = i and add a field (once, twice, etc) with necessary value

If you want to calc that in the runtime, you'll definitely need calc. dimension which is not a best choice in a large amount of data.

Best regards,

Maxim

MK_QSL
MVP
MVP

Create a Pivot Table

Dimension

serviceName

Expression

Once

=SUM(Aggr(IF(COUNT(serviceName)=1,1),clientID,serviceName))

Twice

=SUM(Aggr(IF(COUNT(serviceName)=2,1),clientID,serviceName))

3 Times

=SUM(Aggr(IF(COUNT(serviceName)=3,1),clientID,serviceName))

4 Times

=SUM(Aggr(IF(COUNT(serviceName)>3,1),clientID,serviceName))

File enclosed for your reference....

Not applicable
Author

Maxim, thank you for you answer

Yes, I prefer to load it in script. But I have an issue with date, because I need to filter by period. Actually there are clients table, services table and calendar in my model. If I understand correctly, your solution doesn't relate to the service date.

Any ideas?

Not applicable
Author

Thank you, it works well

MK_QSL
MVP
MVP

Glad to help you. Please don't forget to close the thread by selecting appropriate answer.

Not applicable
Author

Your solution is great but I'm looking for script solution, because it works very slow

MK_QSL
MVP
MVP

Data:

LOAD clientID,

     serviceName,

     serviceKey

FROM

[172423.xlsx]

(ooxml, embedded labels, table is Sheet1);

Temp:

Load

  clientID,

  serviceName,

    Count(serviceName) as Flag

Resident Data

Group By clientID,serviceName;

Now create a Straight or Pivot Table

Dimension

serviceName

Expressions

COUNT({<Flag = {1}>}Flag)

COUNT({<Flag = {2}>}Flag)

COUNT({<Flag = {3}>}Flag)

COUNT({<Flag = {">3"}>}Flag)

Not applicable
Author

Thank you.

I want to show the number of times according to the selected period (the excel file has column date). So the number of times is dynamic data (according to period). The script doesn't solve it unfortunatly. Do you have any idea?