Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Customers, Partners & Luminaries only: You're invited to a Data Analytics Roadmap session. Read More
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
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
Highlighted
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
Highlighted
Partner
Partner

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 

Highlighted
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

Highlighted
Creator
Creator

 

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 👍