Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
Please Suggest how to write this in expression
Set TempSum=0;
Set RowCount= 162522;
for(RowCount<= 162522)
if(NoOfPallets <> 0)
TempSum= TempSum+ Pallets;
RowCount++;
Thanks.
Hi,
Why not using Peek()? If you want to get an aggregated value in the script you don't need to loop, you can get it using RangeSum(), Peek(), Previous() and so, as shown in this thread and this post among some others. (Some with working examples).
Hope that helps.
BI Consultant
use the coe below
and reload
Data:
Data:
LOAD [Customer Number] as CustNo,
[Customer Name] as CustName,
[Item Code] as ItemCode,
[Item Description] as ItemDesc,
[Order Number] as OrderNo,
[Order Position] as OrderPosition,
BackOrder ,
[Order Qty] as OrderQty,
[Delivered Qty] as DeliveredQty,
[Invoice Date] as InvoiceDate,
Month([Invoice Date]) as Month,
'Q' & ceil(month([Invoice Date]) / 3) AS Quarter,
[Invoice Number] as InvoiceNo,
[Invoice Amount] as InvoiceAmount,
[Line of Business] as LOB,
[Line Of Business Description] as LOBDesc,
Warehouse,
Pallet,
Carton,
Shrink,
[No Of Pallets] as NoOfPallets,
[No Of Cartons] as NoOfCartons,
[No Of Shrinks] as NoOfShrinks,
Loose
FROM
(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);
Let y= noofrows('Data');
Set TempSum=0;
for i=1 to $(y)
Load
if(NoOfPallets <> 0, TempSum+ NoOfPallets) as TempSum
autogenerate 1;
next i;
try this
Now it is giving different error " Field not found error" .
" NoOfPallets Field Not found"
what about this
Data:
LOAD [Customer Number] as CustNo,
[Customer Name] as CustName,
[Item Code] as ItemCode,
[Item Description] as ItemDesc,
[Order Number] as OrderNo,
[Order Position] as OrderPosition,
BackOrder ,
[Order Qty] as OrderQty,
[Delivered Qty] as DeliveredQty,
[Invoice Date] as InvoiceDate,
Month([Invoice Date]) as Month,
'Q' & ceil(month([Invoice Date]) / 3) AS Quarter,
[Invoice Number] as InvoiceNo,
[Invoice Amount] as InvoiceAmount,
[Line of Business] as LOB,
[Line Of Business Description] as LOBDesc,
Warehouse,
Pallet,
Carton,
Shrink,
[No Of Pallets] as NoOfPallets,
[No Of Cartons] as NoOfCartons,
[No Of Shrinks] as NoOfShrinks,
Loose
FROM
(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);
Let y= noofrows('Data');
Set TempSum=0;
for i=1 to $(y)
Load
if(NoOfPallets <> 0, TempSum+ NoOfPallets) as TempSum
Resident Data;
next i;
Now it is saying "TempSum field is not found".
Hi,
Did you try mi suggestion below? TempSum is not a field in table "Data", hence the error. Probably using $(TempSum) instead because I'm assuming you are referring to the previously set variable TempSum, isn't it?
Regards.
Yes, Your right.
I am not very familiar with qlikview . Hence facing difficulties to write the expression using peak(), rangesum().
Can you please tell me how to write the specified query using peak() and rangesum().
Many Thanks.
tempsum is variable which is always use with $ sign
so use $(TempSum)
or
may be you required to writein single quotes '$(TempSum)'
Hi Sunil,
Now there is no error.
But it is looping .. Taking long long time.
It will loop till 162522.
Hi Sandeepa,
Using the following script, a new field called TempSum will be created and it will be populated with the sum of TempSum, taking into account that if NoOfPallets is equal to zero, the value will be 1, otherwise, it will accumulate from previous values.
Data:
LOAD CustNo,
ItemCode,
OrderNo,
OrderQty,
DeliveredQty,
InvoiceDate,
Month([Invoice Date]) as Month,
'Q' & ceil(month([Invoice Date]) / 3) AS Quarter,
InvoiceNo,
InvoiceAmount,
Pallet,
Carton,
Shrink,
[No Of Pallets] as NoOfPallets,
If([No Of Pallets] <> 0, RangeSum(Peek('TempSum'), 1), 1) AS TempSum,
[No Of Cartons] as NoOfCartons,
[No Of Shrinks] as NoOfShrinks,
Loose
FROM
(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);
However, this field does not make much sense to me as it is, my guess is that you will need the accumulation of NoOfPallets monthly, quarterly or something. Please read and check the working examples and applications in the posts I mentioned below.
Hope that helps.
BI Consultant