Focal Point
[SOLVED] Issue with Week function EOW to sum Dollars weekly

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4277032106

March 30, 2011, 01:56 PM
MMcDonald
[SOLVED] Issue with Week function EOW to sum Dollars weekly
Week function EOW to sum Dollars weekly from Sunday to Saturday. I was trying to get the dollars to sum up for the start of the week to the end of the week based on my code BOW2 to EOW2. I thought if I sorted by EOW2 it would work. Instead it shows the EOW2 date an next to it I added the original date "BUDAT" and as you can see below my code ... my example shows the sort date (EOW2) of 2011/01/08 but 2011/01/08 is not included in my cumulative field I calculated called "RTOTAL"..I am not sure why??? here is my code & sample below:

DEFINE FILE GLPCA
XWEEK1/A8YYMD=BUDAT;
XWEEK2/YYMD=XWEEK1;
EXDATE1/YYMD = XWEEK2;
BOW1/YYMD = DATEMOV(EXDATE1, 'BOW');
EOW1/YYMD = DATEMOV(EXDATE1, 'EOW');
BOW2/YYMD = DATEADD(BOW1, 'DAY', -1);
EOW2/YYMD = DATEADD(EOW1, 'DAY', +1);
END
TABLE FILE GLPCA
SUM KSL
COMPUTE RTOTAL/D12C=IF MPLANT EQ LAST MPLANT THEN KSL+RTOTAL ELSE KSL;
BY MPLANT
BY EOW2
BY EXDATE1
END
-------------------
Here is the output:

PLANT EOW2 EXDATE1 KSL RTOTAL
B02 2011/01/08 2011/01/01 22.10 22
2011/01/02 28.41 51
2011/01/03 -393.86 -343
2011/01/04 7917.33 7,574
2011/01/05 19161.23 26,735
2011/01/06 -11897.47 14,838
2011/01/07 3165.86 18,004
2011/01/15 2011/01/08 442.00 18,446

This message has been edited. Last edited by: Kerry,


8.0.9, Windows
excel / pdf
March 30, 2011, 03:44 PM
Francis Mariani
COMPUTE RTOTAL/D12C=IF MPLANT EQ LAST MPLANT THEN KSL+RTOTAL ELSE KSL;
To use the LAST syntax, the data must be previously sorted in the correct order, i.e. GLPCA must already be sorted by MPLANT.

Please put your code and report within
[code]
[/code]
tags.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 31, 2011, 08:41 AM
MMcDonald
Francis,
The RTOTAL field calculates correctly....the problem is I need to sort the data by plant and the total for each week should be the cumulative total "RTOTAL" from each Sunday to Saturday...as you can see in my report under the code ...even though the endweek(EOW2) is correct that date is NOT included in the week...it's actually in the next week. My problem is how do I sum the dollars from Sunday to Saturday showing the valuse in the report by PLANT across WEEK.
thanks

DEFINE FILE GLPCA
XWEEK1/A8YYMD=BUDAT;
XWEEK2/YYMD=XWEEK1;
EXDATE1/YYMD = XWEEK2;
BOW1/YYMD = DATEMOV(EXDATE1, 'BOW');
EOW1/YYMD = DATEMOV(EXDATE1, 'EOW');
BOW2/YYMD = DATEADD(BOW1, 'DAY', -1);
EOW2/YYMD = DATEADD(EOW1, 'DAY', +1);
END
TABLE FILE GLPCA
SUM KSL
COMPUTE RTOTAL/D12C=IF MPLANT EQ LAST MPLANT THEN KSL+RTOTAL ELSE KSL;
BY MPLANT
BY EOW2
BY EXDATE1
END


REPORT :

PLANT EOW2         EXDATE1       KSL       RTOTAL 
B02  2011/01/08    2011/01/01   22.10         22 
                   2011/01/02   28.41         51 
                   2011/01/03  -393.86      -343 
                   2011/01/04  7917.33     7,574 
                   2011/01/05  19161.23   26,735 
                   2011/01/06  -11897.47  14,838 
                   2011/01/07  3165.86    18,004 
     2011/01/15    2011/01/08  442.00     18,446 




8.0.9, Windows
excel / pdf
March 31, 2011, 09:12 AM
Tewy
Your code is performing as expected. If you print off the value of EOW1 you should be able to see what is happening.

WebFOCUS has calculated the EOW date for the 08/01/2011 as being the 14/01/2011, adding 1 to this date gives you the 15/01/2011 it doesn't move the EOW calculation in any way.

I believe you are supposed to be able to change which day is the start of the week using some combination of the following settings:

SET BUSDAY
SET WEEKFIRST

hopefully someone else who has done this will know the required settings for you.


WF 7.6.11
Output: HTML, PDF, Excel
March 31, 2011, 09:55 AM
MMcDonald
quote:
SET BUSDAY
SET WEEKFIRST


Tewy,
I tried what you suggested....but still getting the same results.

Does anyone have an idea on how to do this??

thanks


8.0.9, Windows
excel / pdf
March 31, 2011, 12:57 PM
Francis Mariani
In your DEFINE, the EOW function calculates the End of Week of a Saturday to be the next Friday, then you add one to get a Saturday, that's why the end of week for 2011/01/08 is 2011/01/15.

I'll try to come up with code to deal with this.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 31, 2011, 01:09 PM
Francis Mariani
Using a supplied sample database, here's a solution. If the difference in days between the Date and the normally calculated End-of-week is 6 (meaning the Date is a Saturday), use the Date as the End-of-week, else use the normally calculated End-of-week + 1 as the End-of-week.

DEFINE FILE CENTQA
EXDATE1/YYMD = PROBLEM_DATE;
EOW1/YYMD = DATEMOV(EXDATE1, 'EOW');
EOW2/YYMD = IF DATEDIF(EXDATE1, EOW1, 'D') EQ 6 THEN EXDATE1 ELSE DATEADD(EOW1, 'DAY', +1);
MPLANT/A3 = PLANT;
KSL/D10 = QTY_IN_STOCK;
END

TABLE FILE CENTQA
SUM
KSL
BY EOW2
BY EXDATE
END



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 31, 2011, 02:17 PM
MMcDonald
Francis
Looks great !!
Thanks fo ryour help.
Matt


8.0.9, Windows
excel / pdf