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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
waleeed_mahmood
Creator
Creator

Comparing AVGs in a table

Hello all,

I have a question I cant seem to solve.

I have a following table in QS.

Parent CompanyPotentialActualCOL D :Share of Wallet (SoW)

COL E:

Total Visits (TVs)

Bucket
Customer A656,1301,019,145155%311
Customer B220,307109,57450%311
Customer C239,464800%34
Customer D416,66777,91519%122
Customer E81,41829,04336%74
Customer F206,897-3,099-1%162
Customer G82,37578,69496%33
Customer H90,5175,4476%112
Customer I306,51314,4675%142
Customer J78,54486,192110%121
Customer K35,9206762%44
Customer L47,89323,25649%63
Customer M013,806-43
Customer N60,82417,71229%112
Customer O95,7852,9343%14
Customer P04,243-03
Customer Q0875-03

 

Share of Wallet = Actual/Potential;

AVG_SoW (COL $E$19 in Below criteria) = 40% found by 

>>>avg(aggr(Actual/Potential ,[Parent Company],[Sales Employee]));

AVG_TVs (COL $D$19 in Below criteria) = 9.76 found by

>>>> sum(aggr(count([Total Visits])/count([Parent Company]),[Parent Company],[Sales Employee]));

What i want to do is generate the Buckets column based on the following criteria:

Note: Col E is SoW and Col D is TVs in above table

=IF(AND(E2 >$E$19,D2>$D$19),"1",
IF(AND(E2>$E$19,D2<$D$19),"2",
IF(AND(E2<$E$19,D2>$D$19),"3", "4")))

My Probelm:

Im getting the following in QS

Parent CompanyPotentialActualCOL D :Share of Wallet (SoW)

COL E:

Total Visits (TVs)

Bucket
Customer A656,1301,019,145155%311
Customer B220,307109,57450%31-
Customer C239,464800%3-
Customer D416,66777,91519%121
Customer E81,41829,04336%7-
Customer F206,897-3,099-1%16-
Customer G82,37578,69496%3-
Customer H90,5175,4476%11-
Customer I306,51314,4675%14-
Customer J78,54486,192110%12-
Customer K35,9206762%4-
Customer L47,89323,25649%6-
Customer M013,806-4-
Customer N60,82417,71229%11-
Customer O95,7852,9343%1-
Customer P04,243-0-
Customer Q0875-0-

 

Your help is greatly appreciated.

Please let me know if your need any clarification.

Thank you.

Labels (2)
1 Solution

Accepted Solutions
waleeed_mahmood
Creator
Creator
Author

Hi Ruben,

Thank you for your reply. my QS script already had them in variables and i was already using the logic you mentioned above and getting those blanks in my post.

However, i was able to make it work by putting TOTAL in the AVG formulas so they dont change with dimensions when i use them in a table.

AVG_SoW = avg(TOTAL aggr(Actual/Potential ,[Parent Company],[Sales Employee]));

AVG_TVs  = sum(aggr(count(TOTAL [Total Visits])/count(TOTAL [Parent Company]),[Parent Company],[Sales Employee]));

 

Thank you for your help.

View solution in original post

2 Replies
rubenmarin

Hi, you can use a variable to store $E$19, like creating a variable vAVG_SoW with value:

=avg(aggr(Actual/Potential ,[Parent Company],[Sales Employee]))

So this variable is calculated outside the table and dimensions won't affect it's result, same for D's expression, the you can use:

IF(avg(aggr(Actual/Potential ,[Parent Company],[Sales Employee]))>$(vAVG_SoW) and sum(aggr(count([Total Visits])/count([Parent Company]),[Parent Company],[Sales Employee]))>$(vAVG_TVs ), '1',
  IF...

If buckets are fixed (not affected by selections) it will be better to have this calculated on script.

waleeed_mahmood
Creator
Creator
Author

Hi Ruben,

Thank you for your reply. my QS script already had them in variables and i was already using the logic you mentioned above and getting those blanks in my post.

However, i was able to make it work by putting TOTAL in the AVG formulas so they dont change with dimensions when i use them in a table.

AVG_SoW = avg(TOTAL aggr(Actual/Potential ,[Parent Company],[Sales Employee]));

AVG_TVs  = sum(aggr(count(TOTAL [Total Visits])/count(TOTAL [Parent Company]),[Parent Company],[Sales Employee]));

 

Thank you for your help.