Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
berryandcherry6
Creator III
Creator III

calculating total in script

Hi,

i have below like table in script

Table:

Load * inline

[ clientID,BatchID

3,12

3,12

3,12

3,13

3,14

3,15

3,13

3,15

];

Table2:

Load * inline

[BatchID,CampID,sales,advertise

12,2,23,21

12,3,4,5

12,4,3,6

13,5,46,87

14,6,12,23

15,7,34,12

13,8,56,2

15,9,23,5

];

Load  (sum(sales)/sum(advertise)) as Percetage,

CampID

Resident Table2  Group By CampID;

This gives me Percentage for each CampID, but i need to get  percentage ( i.e sum(sales)/sum(advertise))  for clientID.

My result should be


clientID  Percetage

3             1.248


Please help me on this


Regards,

Supriya

8 Replies
Anil_Babu_Samineni

You can use, Simple

clientID as Dimension

and expression should be sum(sales)/sum(advertise) // Because, clientID is already associate with you

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
berryandcherry6
Creator III
Creator III
Author

Hi,

But i need to this in script itself. Can i do this in script?

vinieme12
Champion III
Champion III

your data sample doesn't seem right

you have the same client Id repeated for the same batch, which has 3 different rows in the second table this way you will have 3 x 3 rows for the same client id,

is that correct?

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
stabben23
Partner - Master
Partner - Master

Hi,

Change Your script:

Table:

Load * inline

[ clientID,BatchID
  3,12
3,12
  3,12
  3,13
3,14
3,15
3,13
3,15
  ]
;

Table2:
 
Left Join Load * inline //Left Join here
 
[BatchID,CampID,sales,advertise
  12,2,23,21
  12,3,4,5
12,4,3,6
  13,5,46,87
  14,6,12,23
  15,7,34,12
  13,8,56,2
15,9,23,5
]
;
 
New:
Load  (sum(sales)/sum(advertise)) as Percetage,
 
clientID
Resident Table  Group By  clientID; //Group by clientID
 
Drop Table Table; //Drop table

Anil_Babu_Samineni

Check stabben23 Reply

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
berryandcherry6
Creator III
Creator III
Author

Hi Vineeth,

Sorry for delay reply.

Yes, you are right we will have 3 x 3 rows for the same client id, beacuse each client has different batches.

You could see below attached qvf file for better understanding. Let me know if you need more information.

vinieme12
Champion III
Champion III

then first left join to create a single table and then aggregate like Staffan has shown above

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
berryandcherry6
Creator III
Creator III
Author

yes, Anil. Its right according to this simple example,and giving expected output.

But my data model is little complex, here i am not getting how could i incorporate  stabben23 logic.

Can you or Staffan help me to solve this issue i have attached qvf file. Please help me on this.