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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Summing in a Script

I have a table that has part number, plant location and quantity.

But I want the script to return only Part number and the "total" quantity for both plants.

How do I sum the to quantity field. I get an error is I use Sum(Quantity) as TotalQty.

Stephen

7 Replies
Anonymous
Not applicable
Author

Stephen,
Make sure to add GROUP BY:
LOAD
plant,
sum(quantity) as TotalQty
RESIDENT...
GROUP BY plant;

Not applicable
Author

Yes, forgot the Group By.

Thanks

Not applicable
Author

Mike,

Do you have to use "Group By" when using Sum() in a load script under a resident Load?  Im trying to sum up a field prior to my Expression.

PV:

NoConcatenate    //Must do this or it will drop all tables at DROP statement

LOAD

     //Text(WBS) as EVM_WBS,

     Text(WBS) as PV_WBS,

     Text([Task Name]) as [PV_Name],

     Date(Num#(PV_Weeks),'DD-MMM-YY') as EVM_Weeks,   

     PV_Amount,

     TBC as PV_TBC

     Sum(TBC) as BAC

Resident tmpPV;

Thanks!

Brian

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Yes, if you use an aggregation function you must define the fields over which you want to aggregate. You do that with the group by statement.


talk is cheap, supply exceeds demand
Not applicable
Author

ok, thank you gwassenaar.  So in my example would I group by: TBC since that's what I'm summing? 

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Just the exact opposite The fields in the group by statement are all the fields that are not used in an aggregation function. In this case all fields except TBC which gets aggregated in sum(TBC)


talk is cheap, supply exceeds demand
Not applicable
Author

Ok, glad I asked. You learn something new every day.

Thanks!