Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have a problem where I need find if the max date is I have for a trade was on Sunday and if so the deduct 2 days worth of fees. i have tried the below code on load but keep invalid expression. Is this something that can be done?
Load *,
If(WeekDay(Max(MyDate))= 'Sun', Amount1 *((0.2/10000)/365), (Amount1 *((0.2/10000)/365))*-2 ) as Quantity3
Resident tblSecondLoad
Order by CrossRef, MyDate desc;
drop table tblSecondLoad;
Regards
Alan
Weekday() returns an integer between 1-6. In your case, simply replace 'Sun' with '6'. If that doesn't work either, make sure MyDate has a correct Date format and is not a string.
You cannot use the Max() function in a LOAD statement that has no GROUP BY clause (only one exception: use only aggregation functions to create single record with statistics from a full table - see Master Calendar examples)
One solution is to group your records by a "Trade" identifier and then extract the max date. Join the max date back into the table to decide where to subtract 2 days worth of fees.
Peter
Thanks all,
I tried the following but it still doesnt work and also tried to change from Sun to 6 just getting the same error.
Load *,
If(WeekDay(Max(MyDate))= 'Sun', Amount1 *((0.2/10000)/365), (Amount1 *((0.2/10000)/365))*-2 ) as Quantity3
Resident tblSecondLoad
Group by CrossRef;
drop table tblSecondLoad;
Your loading all the fields in load statement (Load *). In this case you need all the fields in your groupby statement. So try without *, load as separate table
The story behind GROUP BY:
Perform a two step approach:
Best,
Peter
have you tried a modification of your script as follows:
Load
If(WeekDay(MyDate)= 'Sun', Amount1 *((0.2/10000)/365), (Amount1 *((0.2/10000)/365))*-2 ) as Quantity3;
Resident tblSecondLoad;
drop table tblSecondLoad;
Please mark this answer as correct and complete if this helps.
Thanks