Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
zanhribar
Contributor
Contributor

Calculating average from calculated value

Hello Qlik community I have a question:

First I have fields like plan, sales, employees and column parent where the employees that have same supervisor .

The data I have is I have employee A and employee B and the employee C is their supervisor.

 

Employee A made =5 sales and his plan =2 and employee B made =3 sales and his plan was =2.

Now based on the data I provided the first employee made 250% and the second made 150% based on sales/plan.

But since we have upper limit of 200% the this end with employee A= 200% and employee B =150%

This is the syntax that I used to calculate this precentages and end up with those number(200%,150%):

If (num (sum({<TABLE= {'confirm'}, product={'AA','BB'}>}CAL)-[PLAN])/[PLAN]*100+100<0,0

     If (num (sum({<TABLE= {'confirm'}, product={'AA','BB'}>}CAL)-[PLAN])/[PLAN]*100+100> kap( this is variablewhich has value 200),kap

(sum({<TABLE = {'confirm'}, product= {'AA','BB'}>}CAL)- [PLAN]) / [PLAN]*100+100

 

Now here comes my problem I also have to calculate average for supervisor (employee C)--> which in this case would be 175%, but how to I achieve that??

 

I tried with this syntax:

if( function='UP',     -->(which means parent)

   if( ( sum(total <parent> aggr(sum({<TABLE= {'confirm'}, product= {'AA','BB'}>}CAL), parent)) - sum(total <parent> aggr(sum([PLAN]), parent))) / sum(total <parent> aggr(sum([PLAN]), parent))*100+100 < 0, 0,

       if( ( sum(total <parent> aggr(sum({<TABLE= {'confirm'}, product= {'AA','BB'}>}CAL), parent)) - sum(total <parent> aggr(sum([PLAN]), parent))) / sum(total <parent> aggr(sum([PLAN]), parent))*100+100>kap,kap

            ( sum(total <parent> aggr(sum({<TABLE= {'confirm'}, product= {'AA','BB'}>}CAL), parent)) - sum(total <parent> aggr(sum([PLAN]), parent))) / sum(total <parent> aggr(sum([PLAN]), parent))*100+100

But the problem with this is that for supervisor I get value=200% which is incorrect.

 

Than I also tried with  creating variables

- totalplan -->sum(PLAN)

-totalst --> sum({<TABLE={'confirm'},product={'AA','BB'}>}CAL)

if( function='UP',     -->(which means parent)

AVG(

   aggr(

      if( (sum(total <parent> aggr($[totalst], parent)) -sum(<parent> $[totalplan]))/sum(total <parent>            $[totalplan])*100+100<0,0,

          if((sum(total <parent> aggr($[totalst], parent)) -sum(<parent> $[totalplan]))/sum(<parent>$[totalplan])*100+100> kap,kap

              (sum(total <parent> aggr($[totalplan], parent))-sum(<parent>$[totalplan]))/sum(<parent>$[totalplan])*100+100

)),parent

)

)

But in this case the result is =-

Labels (1)
3 Replies
Aditya_Chitale
Specialist
Specialist

@zanhribar ,

created sample data on my end. Hope this is what you want:

Aditya_Chitale_0-1678083668567.png

Aditya_Chitale_1-1678083700322.png

 

Expression used (modify according to your data):

sum(aggr(if(sum(Sales)/sum(Plan)>2, 2, sum(Sales)/sum(Plan)),employee))

/

count(parent)

 

Regards,

Aditya

 

zanhribar
Contributor
Contributor
Author

Hello, 

Thank you for an answer. 
 

The problem is that my employees and their parent are separated in the same column. 
that column is named function and if one is parent he has function='UP' and if it is employee he has function='FO'. I also have column named parent which is grouped colum so all employees + their parent have the same mark... employee A,B and their supervisor C have 'B1' employee D,F,E and their parent G have 'B2', and so on...

Aditya_Chitale
Specialist
Specialist

Hi @zanhribar ,

Sorry for the late reply but if possible can you share sample data ?

Regards,

Aditya