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] Calculate difference of fields from 2 ACROSS sections

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Calculate difference of fields from 2 ACROSS sections
 Login/Join
 
Member
posted
Hi all,

This is my first time to this forum and it's my first time posting as well. Hope I explain everything clearly.

I have been learning WebFOCUS for 3 months and I am having trouble completing the report I am building now. There are 2 stores in the across section and I am trying to calculate, at the very right hand side of the table, the Sales % variance and the OH % variance between these 2 stores. Will this be possible to accomplished?

Store 1
CLASS "Sales "Sales "OH
Last week" % cont" Inventory" "OH
% cont" "Sales
Last week" "Sales
% cont" "OH
Inventory" "OH
% cont" "SALES %
VARIANCE" "OH %
VARIANCE"
A x y r t = x - r = y - t
B " "
C " "

Please find my current code now.
TABLE FILE INVENTORY_DAILY_SNAPSHOT
SUM CLASS
SALES AS 'Sales,Last week'
COMPUTE sales_pct/D12.2%=Sales / TOT.Sales * 100 ; AS 'Sales,% Cont'
INVENTORY AS 'OH,Inventory'
COMPUTE OH_pct/D12.2%=INVENTORY / TOT.INVENTORY * 100 ; AS 'OH,% Cont'
BY CLASS NOPRINT
ACROSS Stores  

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


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Virtuoso
posted Hide Post
Henry,
It is not very clear what you are trying to accomplish.
Could you put your expalantions between the code tags. I'm afraid that all your dbl-quotes have garbled your description.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Expert
posted Hide Post
Put your COMPUTEs "after" the ACROSS...

If you want them in the order that you have, HOLD the data and calculate the data into the columns you have BY CLASS BY STORE and TABLE the HOLD file...


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Member
posted Hide Post
Sorry Danny....Maybe it is clearer to look at the code only because the table I pasted didn't display correctly...

I have rearranged the order of my code and added the computes TOTAL = C2 - C5 at the end which is what I am trying to calculate...
Where I want that column to calculate the difference between column 2 ('Sales,% Cont' of store 1) and column 5 ('Sales,% Cont' of store 2)...

Hope this clears out any confusions...


TABLE FILE INVENTORY
BY CLASS
ACROSS Stores
Sales AS 'Sales, Last week'
COMPUTE sales_pct/D12.2%=sales / TOT.sales * 100 ; AS 'Sales,% Cont'
INVENTORY AS 'OH,Inventory'
COMPUTE OH_pct/D12.2%=INVENTORY / TOT.INVENTORY * 100 ; AS 'OH,% Cont'
COMPUTE TOTAL = C2 - C5
END


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Expert
posted Hide Post
  
TABLE FILE INVENTORY
SUM 
   COMPUTE XSALE/D12.2 = SALES; NOPRINT
   COMPUTE XINVENTORY/D12.2 = INVENTORY; NOPRINT
  BY CLASS
SUM
   SALES
   INVENTORY
     COMPUTE SALES_PCT/D12.2% = SALES / XSALE * 100 ; 
     COMPUTE OH_PCT/D12.2%=INVENTORY / XINVENTORY * 100 ;
     COMPUTE XTOTAL/D12.2 = SALES - INVENTORY;
  BY CLASS
  BY STORES
 ON TABLE HOLD AS HOLD1
END
-RUN
TABLE FILE HOLD1
PRINT 
     SALES     AS 'Sales, Last week'
     SALES_PCT AS 'Sales,% Cont'
     INVENTORY AS 'OH,Inventory'
     OH_PCT    AS 'OH,% Cont'
     XTOTAL    AS 'Total'
  BY CLASS NOPRINT
    ACROSS STORES
END
-EXIT


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Member
posted Hide Post
I am sorry Tom... I think there are still a lot to learn for this Focus languauge, because tried to use your code and replace the field and datasource name with the real ones and it did not work.

Nevertheless, I found a way to have the message board display my table model correctly. Please find below. To simplify things, I took off the ON inventory column and it % contribution column...

	Store 1				Store 2					
CLASS	Sales Last week	   Sales % cont 	Sales Last week	  Sales % cont  	% cont VARIANCE
A				x				y		= x - y
B
C


What I really want to do it is to add a column after the across table to calculate the sales % cont and OH % cont difference between 2 stores... I think this should be pretty easy, but as I am still new to WebFOCUS, this gives me a big headache...

Please also find below the code with real field names I am using now... I appreciate if you can modify from this code so I can make sure to copy yours to my report and run directly without having to modify your code myself that might screw it up... Hope I am not asking too much..

TABLE FILE INVENTORY_DAILY_SNAPSHOT
BY INVENTORY_DAILY_SNAPSHOT.PRODUCTS_HIERARCHY_INFO.DWD_PRODUCTS_CLASS
ACROSS v_store_region_all AS 'Stores'
SUM v_last_week_sales AS 'Sales, Last week'
COMPUTE v_sales_pct_cont/D12.2%=v_last_week_sales / TOT.v_last_week_sales * 100 ; AS 'Sales,% Cont'
INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH AS 'OH,Inventory'
COMPUTE v_OH_pct_cont/D12.2%=INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH / TOT.INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH * 100 ; AS 'OH,% Cont'


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Expert
posted Hide Post
Try this:

 
TABLE FILE INVENTORY_DAILY_SNAPSHOT
SUM
   COMPUTE TOT_SALES/D12.2 = v_last_week_sales; NOPRINT
   COMPUTE TOT_INV/D12.2   = DWF_INV_OH; NOPRINT
  BY DWD_PRODUCTS_CLASS
SUM
   v_last_week_sales
   DWF_INV_OH
    COMPUTE v_sales_pct_cont/D12.2%=(v_last_week_sales / TOT_SALES) * 100 ; 
    COMPUTE v_OH_pct_cont/D12.2%=(INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH / TOT_INV) * 100 ; 
	COMPUTE X_VAR/P6.2% = v_sales_pct_cont - v_OH_pct_cont;
  BY DWD_PRODUCTS_CLASS
  BY v_store_region_all
 ON TABLE HOLD AS HOLD1
END
-RUN
TABLE FILE HOLD1
SUM
   v_last_week_sales AS 'Sales, Last week'
   v_sales_pct_cont  AS 'Sales,% Cont'
   DWF_INV_OH        AS 'OH,Inventory'
   v_OH_pct_cont     AS 'OH,% Cont' 
   X_VAR             AS '% cont VARIANCE'
  BY DWD_PRODUCTS_CLASS
        ACROSS v_store_region_all AS 'Stores'
END
-EXIT

This message has been edited. Last edited by: Tom Flynn,


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Member
posted Hide Post
Thank you again Tom, I think I am getting there but it still didnt work yet.

I copied your code and replaced it with my TABLE FILE commande before the filters and styling commands. But it gives me an error message of

"0 ERROR AT OR NEAR LINE 21 IN PROCEDURE ADHOCRQ FOCEXEC *
(FOC253) INVALID FORMAT SPECIFICATION ON LEFT HAND SIDE: P6.25
(FOC009) INCOMPLETE REQUEST STATEMENT
BYPASSING TO END OF COMMAND
0 ERROR AT OR NEAR LINE 27 IN PROCEDURE ADHOCRQ FOCEXEC *
(FOC205) THE DESCRIPTION CANNOT BE FOUND FOR FILE NAMED: HOLD1
BYPASSING TO END OF COMMAND"

Where line 21 is
"COMPUTE X_VAR/P6.25 = v_sales_pct_cont - v_OH_pct_cont;"
and line 27 is
"TABLE FILE HOLD1" in my code.

Please find below the code structure of my code after inserting yours... I suspect is because of the END or -EXIT command?

your code
   "
   "
  BY DWD_PRODUCTS_CLASS
        ACROSS v_store_region_all AS 'Stores'
WHERE INVENTORY_DAILY_SNAPSHOT.STORES_INFO.DWD_STORES_DIVISION_CODE EQ 'G';
WHERE INVENTORY_DAILY_SNAPSHOT.PRODUCTS_INFO.DWD_PRODUCTS_SEASON_CODE EQ &DWD_PRODUCTS_SEASON_CODE.(OR(<60>,<61>,<62>,<63>,<64>,<65>,<66>,<67>,<68>,<69>,<70>,<71>,<72>,<73>,<74>)).Product Season.;
WHERE INVENTORY_DAILY_SNAPSHOT.PRODUCTS_HIERARCHY_INFO.DWD_PRODUCTS_DEPT_CODE EQ '04' OR '05' OR '06' OR '07' OR '08' OR '10' OR '11' OR '12' OR '13' OR '14' OR '15' OR '16' OR '20' OR '22';
ON TABLE PCHOLD FORMAT EXL2K
ON TABLE NOTOTAL
ON TABLE SET PAGE-NUM NOLEAD
ON TABLE SET SQUEEZE ON
ON TABLE SET HTMLCSS ON
ON TABLE SET HTMLENCODE ON
ON TABLE SET EMPTYREPORT ON
ON TABLE SET STYLE *
INCLUDE=IBFS:/CFG/FILE/IBI_HTML_DIR/javaassist/intl/EN/combine_templates/ENgray_theme.sty,$
ENDSTYLE
END
-EXIT

-RUN


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Expert
posted Hide Post
Yes, I didn't have my shift key down; s/b P6.2%


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Member
posted Hide Post
The code works, but Instead of adding only 1 column at the extrem right hand side to calculate the sames variance between the first store. It is adding a column to each store that calculate the variance between the Inventory and the Sales of the same store.

It should be like this
	Store 1				Store 2					
CLASS	Sales Last week	   Sales % cont 	Sales Last week	  Sales % cont  	% cont VARIANCE
A				x				y		= x - y
B
C


It looks like this now
	Store 1									Store 2					
CLASS	Sales Last week	   Sales % cont	 OH inventory	OH % cont   % Cont Variance	Sales Last week	  Sales % cont  OH inventory	OH % cont   % Cont Variance
A				x			   y            = x - y		   	             n                      m           = n - m
B
C


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Expert
posted Hide Post
OK, try this:

  
TABLE FILE INVENTORY_DAILY_SNAPSHOT
SUM
   COMPUTE TOT_SALES/D12.2 = v_last_week_sales; NOPRINT
   COMPUTE TOT_INV/D12.2   = DWF_INV_OH; NOPRINT
  BY DWD_PRODUCTS_CLASS
SUM
   v_last_week_sales
   DWF_INV_OH
    COMPUTE v_sales_pct_cont/D12.2%=(v_last_week_sales / TOT_SALES) * 100 ; 
    COMPUTE v_OH_pct_cont/D12.2%=(INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH / TOT_INV) * 100 ; 
  BY DWD_PRODUCTS_CLASS
  BY v_store_region_all
 ON TABLE HOLD AS HOLD1
END
-RUN
TABLE FILE HOLD1
SUM
   v_last_week_sales AS 'Sales, Last week'
   v_sales_pct_cont  AS 'Sales,% Cont'
   DWF_INV_OH        AS 'OH,Inventory'
   v_OH_pct_cont     AS 'OH,% Cont' 
  BY DWD_PRODUCTS_CLASS
        ACROSS v_store_region_all AS 'Stores'
	COMPUTE X_VAR/P6.2% = v_sales_pct_cont - v_OH_pct_cont; AS '% cont VARIANCE'

END
-EXIT



Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Virtuoso
posted Hide Post
I think one pass on the data is sufficient:
  
-* File henry01.fex
DEFINE FILE CAR
RCOST/D7=RCOST  + 1024;
DCOST/D7=DCOST  - 2096;
END
SET CENT-ZERO=ON
TABLE FILE CAR
SUM TOT.RCOST NOPRINT TOT.DCOST NOPRINT
SUM RCOST COMPUTE R_PCT/P7.2%=RCOST / TOT.RCOST * 100;
    DCOST COMPUTE D_PCT/P7.2%=DCOST / TOT.DCOST * 100;
BY COUNTRY
ACROSS SEATS
COMPUTE 
RVAR/P7.2% = C4 - C8;
DVAR/P7.2% = C6 - C10;
IF SEATS EQ 4 OR 5
END


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Member
posted Hide Post
Hi all,

I was able to get the results by adding 2 more lanes to my orginal code...

Here is the code.
TABLE FILE INVENTORY_DAILY_SNAPSHOT
SUM v_last_week_sales AS 'Sales, Last week'
COMPUTE v_sales_pct_cont/D12.2%=v_last_week_sales / TOT.v_last_week_sales * 100 ; AS 'Sales,% Cont'
INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH AS 'OH,Inventory'
COMPUTE v_OH_pct_cont/D12.2%=INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH / TOT.INVENTORY_DAILY_SNAPSHOT.INVENTORY_INFO.DWF_INV_OH * 100 ; AS 'OH,% Cont'
BY INVENTORY_DAILY_SNAPSHOT.PRODUCTS_HIERARCHY_INFO.DWD_PRODUCTS_CLASS
ACROSS v_store_region_all AS 'Stores'
   COMPUTE X_VAR/D12.2% = C3 - C9; AS 'Sales % cont VARIANCE'
   COMPUTE Y_VAR/D12.2% = C6 - C12; AS 'OH % cont VARIANCE'


However... I still dont understand why Sales % cont is at C3 for store 1 and C9 for store 2... then OH % Cont is at C6 for store 1 and C12 for store 12......

Also, I dont understand where I should put the last 2 computes so it is not display in every ACROSS field.

Thank you all for your help!


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Gold member
posted Hide Post
You said you were able to get the results that you wanted but I was curious if the following also might work for you as well.

DEFINE FILE CAR
CLASS/A1=IF COUNTRY EQ 'ENGLAND' OR 'FRANCE' THEN 'A'
ELSE IF COUNTRY EQ 'ITALY' OR 'JAPAN' THEN 'B'
ELSE '';
STORE_NAME/A63=IF COUNTRY EQ 'ENGLAND' OR 'ITALY' THEN 'Store1'
ELSE IF COUNTRY EQ 'FRANCE' OR 'JAPAN' THEN 'Store2'
ELSE '';

RCOST_STORE_1/D7=IF STORE_NAME EQ 'Store1' THEN RCOST ELSE 0;
RCOST_STORE_2/D7=IF STORE_NAME EQ 'Store2' THEN RCOST ELSE 0;
RCOST_TOT/D7=RCOST;
END

TABLE FILE CAR
SUM
RCOST_STORE_1 NOPRINT
RCOST_STORE_2 NOPRINT
RCOST_TOT NOPRINT
BY CLASS

SUM
RCOST
COMPUTE RCOST_PERCENT/D8.2%=(RCOST/RCOST_TOT)*100;
BY CLASS
ACROSS STORE_NAME
COMPUTE RCOST_DIF/D7=RCOST_STORE_1-RCOST_STORE_2;
COMPUTE RCOST_DIF_PER/D8.2%=((RCOST_STORE_1/RCOST_TOT)*100)-((RCOST_STORE_2/RCOST_TOT)*100);
WHERE CLASS NE '';
END


WF: 8201, OS: Windows, Output: HTML, PDF, Excel
 
Posts: 78 | Registered: November 08, 2010Report This Post
Virtuoso
posted Hide Post
Henry,

I shall try to explain using my example which I have annotated:
  
-* The DEFINE is to create RCOST and DCOST values sufficiently different
DEFINE FILE CAR
RCOST/D7=RCOST  + 1024;
DCOST/D7=DCOST  - 2096;
END
SET CENT-ZERO=ON
-* The "C" notation is the internal numbering that FOCUS provides for verb objects. 
-* BY fields are not given an internal number because they are supposed to be single within a TABLE request
-*
TABLE FILE CAR
-* The first SUM verb has no BY fields 
SUM 
-* TOT.RCOST is field C1
    TOT.RCOST NOPRINT 
-* TOT.DCOST is field C2
    TOT.DCOST NOPRINT
-* The second SUM has a BY and an ACROSS
-* The Across has 2 values (SEATS=4, 5), hence all the verb objects of the SUM are multiplied by 2
-*
SUM
-* RCOST is field C3 for SEATS=4, then C7 for SEATS=5
    RCOST 
-* R_PCT is field C4 for SEATS=4, then C8 for SEATS=5
    COMPUTE R_PCT/P7.2%=RCOST / TOT.RCOST * 100;
-* DCOST is field C5 for SEATS=4, then C9 for SEATS=5
    DCOST 
-* D_PCT is field C6 for SEATS=4, then C10 for SEATS=5
    COMPUTE D_PCT/P7.2%=DCOST / TOT.DCOST * 100;
BY COUNTRY
ACROSS SEATS
-* The last COMPUTE, after the ACROSS is calculated once and 2 columns are added to the report 
COMPUTE 
RVAR/P7.2% = C4 - C8;
DVAR/P7.2% = C6 - C10;
IF SEATS EQ 4 OR 5
END

I hope this clarifies it for you.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Member
posted Hide Post
Hi Crymsyn,

As I am now to FOCUS and the code you gave me is using some reference field name, I am not too sure if I can have your code working properly after replacing the field names with the real ones from my data sources. I will try my best and let you know after I tried.


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Member
posted Hide Post
Hi Danny,

Thank you for your detailed explanation. Now I understand how the columns are placed from your example. I have 2 more doubts if you can explain to me too.

1- I tried you code before but FOCUS gave me the first error about line
RCOST/D7=RCOST  + 1024;
DCOST/D7=DCOST  - 2096

Saying that I can not use constant (1024 & 2096) in the code if I remember correctly.

2. As you mentioned "The last COMPUTE, after the ACROSS is calculated once and 2 columns are added to the report."
Why is that? is it because the COMPUTE is placed after across? What should be the order of the lines...? I am not good at the FOCUS syntax...

Thank you for your help again.

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


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 2012Report This Post
Virtuoso
posted Hide Post
Henry,

1. If you got an error, I suggest there is a typo somewhere...

2. Yes, when COMPUTE is placed after ACROSS the computation is placed after all the verb objects of all the ACROSS values.

3. Well... to get better at FOCUS syntax, I suggest, a laptop with WebFOCUS installed, a place far away, and leaving your cellphone at home! Cool


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Member
posted Hide Post
LOL thank you for all your help.

Special thanks for your 3rd suggestion. I will consider that Wink


WebFOCUS 7.7.02
Windows, All Outputs
 
Posts: 20 | Registered: June 12, 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] Calculate difference of fields from 2 ACROSS sections

Copyright © 1996-2020 Information Builders