Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
mikegrattan
Creator III
Creator III

Problem summing an average in pivot table

I have a pivot table with a measure that calculates the average number of boxes shipped per day by each warehouse.  I'd like to get a sum of those averages by warehouse so I can then do a percentage of total calculation.  The current expression to get average of boxes per day is:

Avg(Aggr(Sum({$<RecordType={"LOAD"}>} UnitsLoaded),Date))

I've tried modifying that expression in order to get the total for all warehouses but haven't been able to get any variations to work as I expect.

Avg(Aggr(Sum({$<RecordType={"LOAD"},Warehouse=>} UnitsLoaded),Date))

Avg(Aggr(Sum({1<RecordType={"LOAD"}>} UnitsLoaded),Date))

Sum(Aggr(Avg({$<RecordType={"LOAD"}>} UnitsLoaded),Date))

etc.

pivot table average totals by Warehouse.jpg

80 Replies
mikegrattan
Creator III
Creator III
Author

Hi Vijay.

ShipQty is the same as UnitsLoaded (it's just a Sum(UnitsLoaded) in the table that I exported to the Excel file).  I couldn't send a full year of data due to the row limitation in Excel.  I'll look at creating a QVD instead so you can get all the data needed for this calculation to work.

vvira1316
Specialist II
Specialist II

Hi Mike,

QVD is not required. I was just trying to see if you were to do that calculation in an Excel Worksheet, how you would have done that. Understanding that would have allowed to come up with logic in Qlik.

BR,

Vijay

mikegrattan
Creator III
Creator III
Author

Here's just 2016 data in a QVD and a sample application QVF with a straight table  Notice in the straight table I can get a daily average by warehouse, and get a sum of those averages in the Totals line.  I'd like to be able to get that same total in a pivot table too.

Thanks,

Mike

mikegrattan
Creator III
Creator III
Author

I have not attempted to do the same thing in an Excel workbook. 

vvira1316
Specialist II
Specialist II

Hi Mike,

Using 2016 QVD I found that there are duplicate records

I used following script

NoConcatenate

CoolerOut2016:

LOAD SalesOrder,

     OrdNumKey,

     RecordType,

     CaseNumber,

     CaseKey,

     OrderKey,

     Warehouse,

     WageLocationKey,

     OrderType,

     ReceiptType,

     ItemNumber,

     ShipToNumber,

     ShipToCustomer,

     SoldToNumber,

     SoldToCustomer,

     GroupNumber,

     GroupCustomer,

     PickDate,

     UnitsLoaded,

     PickFlag,

     ItemOrderPallets,

     WageWHUnitsLoaded,

     CheckinHour,

     Hour,

     ShipHour,

     MinutesToLoad,

     HoursToLoad,

     UnitsPerHr,

     CheckinTimestamp,

     BackinTimestamp,

     BeginLoadTimestamp,

     Date,

     DayOfWeek,

     LoadDateHour,

     EndLoadTimestamp,

     ShipTimestamp,

     TruckNumber,

     ItemsOnOrder,

     StagedItemsOnOrder,

     CartonsOnOrder,

     PalletsOnOrder,

     AutoNumber(RowNo()) as RecNumber

FROM

CoolerOut2016.qvd

(qvd);

NoConcatenate

SAL_Warehouse_Info:

LOAD Warehouse,

Date as GroupDate,

Sum(UnitsLoaded) as UnitsLoadedByDate,

Count(RecNumber) as RecCountByDate

Resident CoolerOut2016

Group By Warehouse, Date

Order By Warehouse, Date;

AutoNumber(RowNo()) as RecNumber shows 1,296,935 records


TableOutput.JPG


If I don't use this field in the table and export data (I exported using selective warehouse to limit number of rows won't exceed Excel limit) then it gives me following. I've attached excels for your reference.


   

WarehouseQVD RowsQlikTableDiff
HOL38483vs3840578
HUR68422vs68279143
OXN51601vs51486115
SAL634141vs6315922549
SBF55554vs55313241
SSS33318vs33093225
VBF9719vs967544
YSS19926vs19809117
YUM385771vs3842061565
129693512918585077

For warehouse SAL the UnitsLoaded Sum is 22,808,466, there are 297 different dates contributing to that sum. The Average comes to 76,796

AWHUnitsNDate.JPG

I'm not sure why Qlik shows 1138 without any selection in Qlik. If I make selection of SAL then it shows 76,796 the formula I'm using is following

Avg(Aggr(Sum({<RecordType={'Load'}>} UnitsLoaded), Date))

Please refer to following screenshots

AllWarehouse.JPG   SALWarehouse.JPG

Can't understand this behavior and don't know what the reasoning for this can be

Also why some of the warehouses are not showing up as can be seen in the screen shot above

Can you please verify numbers, also come up with formulas in excel to get the numbers you have to arrive at. That will help in strategy we should take to come up with solution.

sunny_talwar

This is a typical problem of Grain Mis-match

Pitfalls of the Aggr function

Try this expression and see what you get (still might not be perfect just because averages Average – Which average? are sort of annoying)

Avg(Aggr(Sum({<RecordType={'Load'}>} UnitsLoaded), Date, Warehouse))

vvira1316
Specialist II
Specialist II

attachments

vvira1316
Specialist II
Specialist II

Yes, that changed

NewAvg.JPG

vvira1316
Specialist II
Specialist II

Sunny,

Now how to get total 229,653 across all warehouses as second expression. That's sort of Mike's need, may not be exact but similar.

sunny_talwar

Can you post the qvw instead of excel or is it too big?