Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
ljackson
Contributor

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
MVP
MVP

Re: max(Date) Group By Load Script Error

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
Partner
Partner

Re: max(Date) Group By Load Script Error

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 

MVP
MVP

Re: max(Date) Group By Load Script Error

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

ljackson
Contributor

Re: max(Date) Group By Load Script Error

 

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 👍