Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Kashia1122
Contributor II
Contributor II

Count, Sum, Divide

Hello,

I hope someone will be able to help me

Kashia1122_0-1613752876847.png

 

I have a table with 4 columns.

Kashia1122_1-1613752877068.png

 

id -> is the product number; Exp_1, Exp_2, Exp_3 is part of the product.

I need to present data in a table where there will be one column containing data from columns (Exp_1, Exp_2, Exp_3) and number of occurrences of values ​​from column Exp_1, Exp_2, Exp_3

for example, for one id in the Exp_1 column I have the value A and in the Exp_2 column I have the value A. My result for A in the new column should be 1 because I count the amount A in all columns for one id and divide by the number of non-empty columns fields for one id

for example, for an id of 4, C should be 0.5 and A 0.5.

finally I need the sum of the values ​​in the new column (number Exp)

Kashia1122_2-1613752877082.png

 

 

2 Solutions

Accepted Solutions
Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    id, Exp1, Exp2, Exp3
    1, A, A, 
    2, B, , 
    3, A, B, A
    4, C, A, 
    5, A, C, B
    6, C, , 
];

tab1X:
CrossTable(Exp,Value)
LOAD * Resident tab1;

Left Join(tab1X)
LOAD id, Count(If(Len(Value)>0,Value)) As C1
Resident tab1X
Group By id;

Left Join(tab1X)
LOAD id, Value, Count(If(Len(Value)>0,Value)) As C2
Resident tab1X
Group By id, Value;

Drop Table tab1;

View solution in original post

Saravanan_Desingh

I think, I should use AGGR here. But please confirm the sum for A.

commQV09.PNG

View solution in original post

5 Replies
Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    id, Exp1, Exp2, Exp3
    1, A, A, 
    2, B, , 
    3, A, B, A
    4, C, A, 
    5, A, C, B
    6, C, , 
];

tab1X:
CrossTable(Exp,Value)
LOAD * Resident tab1;

Left Join(tab1X)
LOAD id, Count(If(Len(Value)>0,Value)) As C1
Resident tab1X
Group By id;

Left Join(tab1X)
LOAD id, Value, Count(If(Len(Value)>0,Value)) As C2
Resident tab1X
Group By id, Value;

Drop Table tab1;
Saravanan_Desingh

In the Chart:

Sum(C2/C1)

commQV07.PNG

Saravanan_Desingh

I think, I should use AGGR here. But please confirm the sum for A.

commQV09.PNG

Kashia1122
Contributor II
Contributor II
Author

Thank you Saran7de 🙂 it is working perfectly. This is what I needed. I used AGGR.

Saravanan_Desingh

If it answered, please close the thread by selecting the solution