Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
jduenyas
Specialist
Specialist

Set analysis help

Hello all

I have a table as such:

   

OrderNumberDeptSalesPersonScore_AScore_BScore_C
O_1ClothingChris444
O_2ClothingJanet444
O_3ShoesTerry444
O_4ShoesTerry232
O_4ClothingTerry232
O_5UrethaneAdam423

What will be the average of Score_A disregarding Dept  because for OrderNumber O_4 it has 2 entries.

(The sum of all Score_A, considering Distinct for O_4 is 18. Dividing that by 5 distinct OrderNumber yields 3.6 which is the correct answer)

I tried these:

Using set analysis :  =Sum({< Dept= >}Score_A) / Count(Distinct OrderNumber) yields 3.333 which is incorrect.

Using set analysis : =Avg({< Dept= >}Score_A) yields 3.333 which is incorrect.

How can I calculate disregarding the Dept ?

Thanks

Josh

1 Solution

Accepted Solutions
engishfaque
Specialist III
Specialist III

Dear Josh,

Kindly find attached document for proper average calculation.

Please have a look into given below article for average,

Average – Which average?

Kind regards,

Ishfaque Ahmed

View solution in original post

4 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi,

Change your script like below

Temp:

LOAD

*

FROM DataSource;

Order:

LOAD DISTINCT

OrderNumber, Dept, SalesPerson

RESIDENT Temp;

Details:

LOAD DISTINCT

OrderNumber, Score_A, Score_B, Score_C

RESIDENT Temp;

DROP TABLE Temp;

Now use below expression

=Sum(Score_A) / Count(Distinct OrderNumber)

OR

=Avg(Score_A)

Hope this helps you.

Regards,

Jagan.

qlikviewwizard
Master II
Master II

I have done the same with the sample data.

Capture.PNG

engishfaque
Specialist III
Specialist III

Dear Josh,

Kindly find attached document for proper average calculation.

Please have a look into given below article for average,

Average – Which average?

Kind regards,

Ishfaque Ahmed

jduenyas
Specialist
Specialist
Author

Thank you Ishfaque

The expression AVG(AGGR(XXXX,YYYY)) did the trick without the need to change the load script and breaking it into 2 separate tables.