Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Next & previous syntax for NumberOrder

Hello,

I'm new at Qlickview and hope anyone can help me with the following:

I have customerdata with customernumbers and ordernumbers and want to know the NumberOrder; meaning per customer if it's the first, second or third (or more) order.

I thought of using next and previous syntax (although i'm not sure what those look like), and tried the following (new formulas in bold):

Load

//    "No_" as DocumentNo

   "Document No_"&'-'&"No_" as DocuItemNo

   , "Sell-to Customer No_"as CustomerNo

   , "Package Tracking No_" as PackageTrackingNo

   , "Promotion Name" as PromotionName

   , "Promotion ID" as PromotionID

   , "Discount Description" as DiscountDescription

   , IF (NEXT(CustomerNo)=CustomerNo, CustomerNo,1) AS OrderCode 

// so for customers who placed more orders, those orders will be coded with 1 and then we can calculate NumberOrder

   , IF (PREVIOUS(CustomerNo)=CustomerNo, PREVIOUS(OrderCode)+1,1) as NumberOrder;   

SQL SELECT  

       "Document No_"

   , "Sell-to Customer No_"   

   , "No_"  

   , "Package Tracking No_"

   , "Promotion Name"  

   , "Promotion ID"

   , "Discount Description" 

FROM "$(DB_DATASOURCE)".dbo."$(DB_COMPANY)$Sales Invoice Line"

ORDER BY "Sell-to Customer No_";

But this is not working... Does anyone have a solution?

Regards,

Eline

10 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Then try with peek function instead of Previous.

CustomerDocument:

Load

//    "No_" as DocumentNo

   "Document No_"&'-'&"No_" as DocuItemNo

   , CustomerNo

   , "Package Tracking No_" as PackageTrackingNo

   , "Promotion Name" as PromotionName

   , "Promotion ID" as PromotionID

   , "Discount Description" as DiscountDescription

   , IF (PEEK('CustomerNo')=CustomerNo, PEEK('NumberOrder')+1,1) as NumberOrder;

SQL SELECT

       "Document No_"

   , "Sell-to Customer No_" as CustomerNo 

   , "No_"

   , "Package Tracking No_"

   , "Promotion Name"

   , "Promotion ID"

   , "Discount Description"

FROM "$(DB_DATASOURCE)".dbo."$(DB_COMPANY)$Sales Invoice Line"

ORDER BY "Sell-to Customer No_";

Celambarasan

Edit:Added single quotes in the peek function. Message was edited by: Celambarasan Adhimulam