Focal Point
SOLVED-ROLLING CALCULATION DISPLAY QUESTION

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

April 12, 2016, 05:29 PM
JulieA
SOLVED-ROLLING CALCULATION DISPLAY QUESTION
I've conducted quite a search on the forum, and I found code on how to create the rolling calculation (and I SO appreciate that). Perhaps I overlooked the obvious answer for the last part of my report. I'd appreciate any guidance.

Q. How do I display only the last year of a rolling calculation at the far right of a tabular report?

Details:

1. I have customer counts for years 2008-2015. I want to display all years' customer counts, along with the year.
2. I need a rolling calculation to determine the five-year difference for the last five years of data only, in this case, the percentage of change from 2010 to 2015 only. See PERCENT_LAG_5
3. I need a rolling calculation to determine the one-year difference for the last year of data only, in this case, the percentage of change from 2014 to 2015 only. See PERCENT_LAG_1
4. After I add customer count data for 2016, I want the calculation to automatically adjust to calculate 2011 to 2016 for the five-year difference and 2015 to 2016 for the one-year difference.

Here's my code thus far:

TABLE FILE MV_CUSTOMERS
SUM
MV_CUSTOMERS.MV_CUSTOMERS.HEADCOUNT/D10
COMPUTE LAG_1/D10 = IF STORE EQ LAST STORE THEN LAST HEADCOUNT ELSE 0;
COMPUTE LAG_2/D10 = IF STORE EQ LAST STORE THEN LAST LAG_1 ELSE 0;
COMPUTE LAG_3/D10 = IF STORE EQ LAST STORE THEN LAST LAG_2 ELSE 0;
COMPUTE LAG_4/D10 = IF STORE EQ LAST STORE THEN LAST LAG_3 ELSE 0;
COMPUTE LAG_5/D10 = IF STORE EQ LAST STORE THEN LAST LAG_4 ELSE 0;
COMPUTE PERCENT_LAG_1/D10.1% = IF LAG_5 NE 0 THEN ( HEADCOUNT - LAG_1 ) / LAG_1 * 100 ELSE 0; AS '%,One Year Diff'
COMPUTE PERCENT_LAG_5/D10.1% = IF LAG_5 NE 0 THEN ( HEADCOUNT - LAG_5 ) / LAG_5 * 100 ELSE 0; AS '%,Five Year Diff'
BY LOWEST MV_CUSTOMERS.MV_CUSTOMERS.REGION
BY MV_CUSTOMERS.MV_CUSTOMERS.STATE
BY LOWEST MV_CUSTOMERS.MV_CUSTOMERS.STORE
BY LOWEST MV_CUSTOMERS.MV_CUSTOMERS.YEAR
WHERE ( MV_CUSTOMERS.MV_CUSTOMERS.SALES_TERM EQ 'CY' );

I placed the above in a HOLD file.

The second part of my code goes like this:

TABLE FILE EXPORTHC
SUM
EXPORTHC.EXPORTHC.HEADCOUNT
EXPORTHC.EXPORTHC.PERCENT_LAG_1
EXPORTHC.EXPORTHC.PERCENT_LAG_5
BY EXPORTHC.EXPORTHC.REGION
BY EXPORTHC.EXPORTHC.STATE
BY EXPORTHC.EXPORTHC.STORE
ACROSS LOWEST EXPORTHC.EXPORTHC.YEAR

That's as far as I've gotten. I get the calculations I want, but I get them for other years I don't want such as the five-year difference between 2008-2013. I only want the last five-year difference and the last one-year difference to appear in my report at the far right.

I'm using Dev Studio and am on WebFocus version 8.0.09, and I've only been using WebFocus since September 2015.

Thank you in advance.

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


WebFocus 8.2.04
WebFocus 8.2.04

April 13, 2016, 05:59 AM
Tony A
If I understand you correctly, then this should do what you need -

TABLE FILE EXPORTHC
  SUM MAX.PERCENT_LAG_1 AS 'Lag 1' NOPRINT
      MAX.PERCENT_LAG_5 AS 'Lag 5' NOPRINT
   BY REGION  AS 'Region'
   BY STATE   AS 'State'
   BY STORE   AS 'Store'
  SUM HEADCOUNT AS 'Head Count'
   BY REGION  AS 'Region'
   BY STATE   AS 'State'
   BY STORE   AS 'Store'
ACROSS YEAR AS 'Year'
COMPUTE LAG_1/D10.1% = MAX.PERCENT_LAG_1; AS 'Lag 1'
COMPUTE LAG_5/D10.1% = MAX.PERCENT_LAG_5; AS 'Lag 5'
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
  grid=off, size=10, $
ENDSTYLE
END
-RUN


T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
April 13, 2016, 09:12 AM
JulieA
Tony,

It's so very close!

The format is perfect; however, the lag percentages are taking the maximum value of my lag percentages from my hold file instead of the last year.

For example, for the first line of my data, the hold file came up with three lag_1 values of 1.2, 2.7 and .1, respectively for 2013, 2014, and 2015. I want the last value of .1. The code you provided takes the maximum value of 2.7.

Any thoughts?

And thank you for your previous help!


WebFocus 8.2.04
WebFocus 8.2.04

April 13, 2016, 09:24 AM
JulieA
Thank you, Tony.

I changed the MAX references to LST, and I think I got it.


WebFocus 8.2.04
WebFocus 8.2.04

April 13, 2016, 10:12 AM
Tony A
Well done to you Smiler Bearing in mind that I didn't have your data, I obviously took the wrong prefix operator!

It's refreshing that someone actually takes the suggestion and then tries to work it out for themselves a little more. I wish some others would do what you have done Smiler

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10