Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
ljackson
Creator
Creator

max(Date) Group By Load Script Error

I need to load, by customer, the last date a product was ordered.   The below script works fine, but obviously the max(Date) and Group By options are commented out.   

LatestOrders:
NOCONCATENATE LOAD
CustCode,
//Max(Date) as MaxDate,
Date,
Order,
OrderStatusH,
OrderInvStatusD,
ProductCode,
OrderSentqtyD,
ActCostD,
ActWsvD,
ActRsvD,
TaholaDateOrder
RESIDENT TempLatestOrderDetails;

//GROUP BY CustCode, ProductCode;

STORE LatestOrders INTO \\bi\Data\QVD\LatestOrders.qvd (QVD);

DROP Table TempLatestOrderDetails;

 

If I change the script to include the max(Date) and Group By I get an INVALID EXPRESSION error:   

LatestOrders:
NOCONCATENATE LOAD
CustCode,
Max(Date) as MaxDate,
//Date,
Order,
OrderStatusH,
OrderInvStatusD,
ProductCode,
OrderSentqtyD,
ActCostD,
ActWsvD,
ActRsvD,
TaholaDateOrder
RESIDENT TempLatestOrderDetails

GROUP BY CustCode, ProductCode;

STORE LatestOrders INTO \\bi\Data\QVD\LatestOrders.qvd (QVD);

DROP Table TempLatestOrderDetails;

 

I'm missing something obvious ....but can't work it out.  What am I doing wrong?

Many thanks for your help 😁

1 Solution

Accepted Solutions
tresesco
MVP
MVP

All the fields you load along with Max(Date) statement (in the same load statement) need to be there in Group By clause.

Load

             F1,

             Max(Date) as Max,

             F2, F3, .... Fn

from <> Group By F1, F2, F3, ....Fn;                  // You might want to change the field order here.

 

View solution in original post

3 Replies
lironbaram
Partner - Master III
Partner - Master III

hi 

when using group by the fields you load 

need to be either in the group by part or 

loaded inside an aggr functions for example maxstring , only 

tresesco
MVP
MVP

All the fields you load along with Max(Date) statement (in the same load statement) need to be there in Group By clause.

Load

             F1,

             Max(Date) as Max,

             F2, F3, .... Fn

from <> Group By F1, F2, F3, ....Fn;                  // You might want to change the field order here.

 

ljackson
Creator
Creator
Author

 

Ahhhh ...that makes sense now.    Many thanks

I've simplified the script, and now it works perfectly:

LatestOrders:
LOAD
CustCode,
Max(Date) as MaxDate,
ProductCode
RESIDENT TempLatestOrderDetails

GROUP BY ProductCode, CustCode;

 

Thanks again 👍