Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Easiest Way to Calculate a Trend Value / Standard Deviation for Total Line

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Easiest Way to Calculate a Trend Value / Standard Deviation for Total Line
 Login/Join
 
Gold member
posted
Consider the following example:
  
DEFINE FILE GGSALES
QTR/QYY = DATE;
END

TABLE FILE GGSALES
SUM 
-*UNITS/D8
DOLLARS/D12M
BY PRODUCT 
ACROSS QTR
ON TABLE PCHOLD FORMAT EXL2K
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     INCLUDE = endeflt,
$
END


It shows sales by product across 8 quarters. What is the easiest way to add one more column to caculate the average variance between quarters. So (q4 1997 sales - q1 1996) sales divided by 8 . For example Biscoitt would have a trend value of -9715.

Thank you

This message has been edited. Last edited by: Joey Sandoval,




Prod/Dev: WebFOCUS 8.0.08 on Windows Server 2008/Tomcat , WebFOCUS DevStudio 8.0.08 on Windows 7 Pro


 
Posts: 94 | Location: Austin, TX | Registered: August 08, 2012Report This Post
Virtuoso
posted Hide Post
One approach:

SET HOLDLIST = PRINTONLY
SET ASNAMES  = ON
-*
DEFINE FILE GGSALES
 QTR/QYY = DATE;
END
-*
TABLE FILE GGSALES
 SUM
  MIN.QTR NOPRINT
  MAX.QTR NOPRINT
-*
 SUM
  DOLLARS/D12M
  CNT.DST.QTR AS 'QTR_CNT'
  COMPUTE FIRST_QTR/D12 = IF (QTR EQ MIN.QTR) THEN DOLLARS ELSE 0 ;
  COMPUTE FINAL_QTR/D12 = IF (QTR EQ MAX.QTR) THEN DOLLARS ELSE 0 ;
 BY PRODUCT 
 BY QTR
 ON TABLE HOLD AS HOLDX
END
-*
TABLE FILE HOLDX
 SUM
  QTR_CNT   NOPRINT
  FIRST_QTR NOPRINT
  FINAL_QTR NOPRINT
 BY PRODUCT
-*
 SUM DOLLARS
 BY PRODUCT
 ACROSS QTR
 COMPUTE VARIANCE/D12M = (FINAL_QTR - FIRST_QTR) / QTR_CNT ;
 ON TABLE PCHOLD FORMAT EXL2K
 ON TABLE SET HTMLCSS ON
 ON TABLE SET STYLE *
  INCLUDE = endeflt, $
 ENDSTYLE
END


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Silver Member
posted Hide Post
here is what i would do:
DEFINE FILE GGSALES
QTR/QYY = DATE;
END

TABLE FILE GGSALES
SUM 
-*UNITS/D8
DOLLARS/D12M
COMPUTE
VARIANCE/D10.2% = IF ((PRODUCT EQ LAST PRODUCT) AND (QTR GT LAST QTR)) THEN (((DOLLARS - LAST DOLLARS) / LAST DOLLARS) * 100) ELSE 0 ;
BY PRODUCT 
ACROSS QTR
ON TABLE PCHOLD FORMAT EXL2K
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     INCLUDE = endeflt,
$
END  


7.7.04
Win2K3, Unix
Oracle 10G,SQL2K,XFOCUS,ESRI,BID,MRE,SELF-SERVICCE
 
Posts: 36 | Location: Melville,NY | Registered: August 09, 2004Report This Post
Gold member
posted Hide Post
Thank you guys for your help! I was able to get 95% of what I need.. now I am just having trouble with the total line. Consider the revised example where I am calculating the Standard Deviation of dollars sold for all 8 quarters along with the overall variance from beginning to end.

 
SET ALL = ON
SET ASNAMES = ON
SET HOLDLIST = PRINTONLY
SET BYDISPLAY = ON
SET HOLDMISS = ON
SET MISSING = ON

DEFINE FILE GGSALES
QTR/QYY = DATE;
END

TABLE FILE GGSALES
SUM 
	MIN.QTR NOPRINT
SUM
DOLLARS/D12.2CM
COMPUTE VARIANCE/D12M MISSING ON = IF MIN.QTR = QTR THEN MISSING ELSE DOLLARS - LAST DOLLARS;
BY PRODUCT 
BY QTR
ON TABLE HOLD AS HOLD1
END

TABLE FILE HOLD1
SUM
VARIANCE NOPRINT
CNT.DOLLARS NOPRINT
ASQ.DOLLARS/D12.2CM NOPRINT
AVE.DOLLARS NOPRINT
COMPUTE PVAR/D12.2 = (ASQ.DOLLARS - (AVE.DOLLARS * AVE.DOLLARS))  * (CNT.DOLLARS / (CNT.DOLLARS-1)); NOPRINT
BY PRODUCT AS 'Product'
SUM DOLLARS/D12M AS 'Sales'
BY PRODUCT AS 'Product'
ACROSS QTR AS 'Period'
COMPUTE STD_DEV/D12M = SQRT(PVAR); AS 'Standard Deviation'
COMPUTE VAR/D12M = VARIANCE; AS 'Trend'
ON TABLE SUMMARIZE 
ON TABLE PCHOLD FORMAT EXL2K
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     INCLUDE = endeflt,
$
END
 


How can I make the Standard Deviation calculation accurate on the total line for all quarters? The total Standard Variation value should equal 134,222. On Table summarize or recompute does not seem to work in this case...




Prod/Dev: WebFOCUS 8.0.08 on Windows Server 2008/Tomcat , WebFOCUS DevStudio 8.0.08 on Windows 7 Pro


 
Posts: 94 | Location: Austin, TX | Registered: August 08, 2012Report This Post
Expert
posted Hide Post
sigh.
first , a standard deviation is valid for normal distributions.
you haven't checked for the shape of the distribution, and don't have enough values to do a test. takes 30.
second, you've used a wildly convoluted way of calculating an sd; i'ld recommend stepping back , and pacing thru the calculations in a more auditable way.
and last, make the TOTAL its own variable. add it to your data set.
if you take off the NOPRINTs, you'll see that your value of N for your total line would be 80, not 8, so just don't do it this way. at all.
DEFINE FILE ibisamp/GGSALES
QTR/QYY = DATE;
END
-RUN
TABLE FILE ibisamp/GGSALES
SUM DOLLARS BY PRODUCT BY QTR ON TABLE HOLD
END
-RUN
TABLE FILE HOLD
SUM
AVE.DOLLARS
BY PRODUCT
SUM DOLLARS AND COMPUTE DIF/D22 =(C2-C1)**2;
BY PRODUCT
BY QTR
ON TABLE HOLD AS HOLD1
END
-* n-1 for sample, n for population
TABLE FILE HOLD1
SUM DIF NOPRINT
CNT.QTR AS N
AVE.DOLLARS AS MEAN

AND COMPUTE STDEV/D12=(C1/(C2-1))**.5;
BY PRODUCT
END




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
 
Posts: 3811 | Location: Manhattan | Registered: October 28, 2003Report This Post
Virtuoso
posted Hide Post
Woow..Susannah

I loved the Sigh...

Math was always my favourite at school...

Good you saw this mistake




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

 
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Report This Post
Gold member
posted Hide Post
Thank you Susannah. I was able to use your advice to write a solution by calculating the total in it's own dataset and joining it to the quarterly dataset using a more statement. Although, you thought my Std Deviation calculation was convoluted, I disagree. I thought the multiverb solution was more elegant and effecient because it used less hold files and built-in ASQ prefix. Wink

 
SET ALL = ON
SET ASNAMES = ON
SET HOLDLIST = PRINTONLY
SET BYDISPLAY = ON
SET HOLDMISS = ON
SET MISSING = ON

DEFINE FILE GGSALES
QTR/QYY = DATE;
END

TABLE FILE GGSALES
SUM
	MIN.QTR NOPRINT
SUM
DOLLARS/D12.2CM
COMPUTE VARIANCE/D12M MISSING ON = IF MIN.QTR = QTR THEN MISSING ELSE DOLLARS - LAST DOLLARS;
BY PRODUCT
BY QTR
ON TABLE HOLD AS QTRHOLD
END

TABLE FILE QTRHOLD
SUM
VARIANCE NOPRINT
CNT.DOLLARS  NOPRINT
ASQ.DOLLARS/D12.2CM  NOPRINT
AVE.DOLLARS  NOPRINT
COMPUTE PVAR/D12.2 = (ASQ.DOLLARS - (AVE.DOLLARS * AVE.DOLLARS))  * (CNT.DOLLARS / (CNT.DOLLARS-1)); NOPRINT
COMPUTE STD_DEV/D12M = SQRT(PVAR); AS 'STD_DEV'
COMPUTE VAR/D12M = VARIANCE; 
BY PRODUCT 
SUM DOLLARS
BY PRODUCT 
BY QTR AS 'QTR'
ON TABLE HOLD AS QTRHOLD2 FORMAT FOCUS
END


TABLE FILE GGSALES
SUM MIN.QTR NOPRINT
SUM
DOLLARS/D12.2CM
COMPUTE VARIANCE/D12M MISSING ON = IF MIN.QTR = QTR THEN MISSING ELSE DOLLARS - LAST DOLLARS;
BY QTR
ON TABLE HOLD AS TOTALHOLD
END

DEFINE FILE TOTALHOLD
PRODUCT/A16 = 'Total';
END

TABLE FILE TOTALHOLD
SUM
VARIANCE NOPRINT
CNT.DOLLARS NOPRINT
ASQ.DOLLARS NOPRINT
AVE.DOLLARS NOPRINT
COMPUTE PVAR/D12.2 = (ASQ.DOLLARS - (AVE.DOLLARS * AVE.DOLLARS))  * (CNT.DOLLARS / (CNT.DOLLARS-1)); NOPRINT
COMPUTE STD_DEV/D12M = SQRT(PVAR); AS 'STD_DEV' 
COMPUTE VAR/D12M = VARIANCE; 
SUM DOLLARS
BY PRODUCT
BY QTR AS 'QTR'
ON TABLE HOLD AS TOTALHOLD2 FORMAT FOCUS
END


TABLE FILE QTRHOLD2
PRINT 
*
ON TABLE HOLD AS FINALHOLD FORMAT FOCUS
MORE 
FILE TOTALHOLD2
END


TABLE FILE FINALHOLD
SUM 
COMPUTE STD_DEV2/D12M = FST.STD_DEV; NOPRINT
COMPUTE VAR2/D12M = FST.VAR; NOPRINT
BY PRODUCT

SUM DOLLARS
BY PRODUCT
ACROSS QTR

COMPUTE STD_DEV3/D12M = STD_DEV2; AS 'Standard Deviation'
COMPUTE VAR3/D12M = VAR2; AS 'Trend'

ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     INCLUDE = endeflt,
$
END

 




Prod/Dev: WebFOCUS 8.0.08 on Windows Server 2008/Tomcat , WebFOCUS DevStudio 8.0.08 on Windows 7 Pro


 
Posts: 94 | Location: Austin, TX | Registered: August 08, 2012Report This Post
Expert
posted Hide Post
disagree all you want, but heed Francis' advice
old coders never leave a mess.
 
Posts: 3811 | Location: Manhattan | Registered: October 28, 2003Report This Post
Gold member
posted Hide Post
I understand the code looks messy, but part of this has to do with the report formatting requirements that I should of mentioned earlier. Our personnel want to see all periods in an across layout, with the Std Deviation and Total Variance calculations as the final 2 columns.

I do tend to try and minimize the amount of hold files used when doing calculations because I've always thought less code is better, but I do understand your point of view of making a more step-by-step design. I will keep this in mind. Thank you.




Prod/Dev: WebFOCUS 8.0.08 on Windows Server 2008/Tomcat , WebFOCUS DevStudio 8.0.08 on Windows 7 Pro


 
Posts: 94 | Location: Austin, TX | Registered: August 08, 2012Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Easiest Way to Calculate a Trend Value / Standard Deviation for Total Line

Copyright © 1996-2020 Information Builders