Focal Point
[CLOSED] Applying a Percentage Calculation from one Row to a Different Row

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

October 24, 2012, 11:59 AM
Joey Sandoval
[CLOSED] Applying a Percentage Calculation from one Row to a Different Row
I know someone on FocalPoint can offer a solution to this challenge. Consider the following code where I am calculating a commission payment and a threshold percentage:

  
DEFINE FILE CAR
COMMISSION/D12.2 = SALES*.035;
END

TABLE FILE CAR

SUM 
DEALER_COST
RETAIL_COST
SALES
COMMISSION
COMPUTE SALES_THRESHOLD_PCT/P8.2 = IF SALES LE 40000 THEN SALES/40000 ELSE 1;
BY COUNTRY
BY CAR

ON COUNTRY SUBTOTAL AS ''
ON COUNTRY SUBFOOT 
" "

ON TABLE SET PAGE-NUM NOLEAD
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     INCLUDE = endeflt,
$
ENDSTYLE
END



Looking at the output, how could I apply the "88%" on the Toyota Line , to all the other commissions payments in the Japan line - in this case the Datsun. So the 1505 amount would get factored by 88%.

The BMW would get reduced to 20% because of the Audi threshold percentage, and so on.

Subtotal commissions for Japan and Germany would ultimately be reduced.

Thank you greatly for your input.

Confused,
Joey Confused

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


October 24, 2012, 01:46 PM
rfbowley
Multi Step procedure with hold files works every time. If I am readiing this correctly you want the lowest, non zero threshold to be applied to all of the countries products. so...

 
TABLE FILE CAR
SUM 
COMPUTE SALES_THRESHOLD_PCT/P8.2 = IF SALES LE 40000 THEN SALES/40000 ELSE 1;
BY COUNTRY
BY CAR
WHERE SALES GT 0
ON TABLE HOLD AS STEP1
END
-RUN

TABLE FILE STEP1
SUM MIN.SALES_THRESHOLD_PCT
BY COUNTRY
ON TABLE HOLD AS STEP2 FORMAT FOCUS INDEX COUNTRY
END
-RUN
 
JOIN CLEAR *

JOIN COUNTRY IN CAR TO COUNTRY IN STEP2 AS J0

DEFINE FILE CAR
COMMISSION/D12.2 = SALES*.035;
END

TABLE FILE CAR
SUM 
DEALER_COST
RETAIL_COST
SALES
COMMISSION
SALES_THRESHOLD_PCT

COMPUTE ADJ_COMMISION/P8.2 = COMMISSION * SALES_THRESHOLD_PCT;
BY COUNTRY 
BY CAR
END
-RUN
 



Robert F. Bowley Jr.
Owner
TaRa Solutions, LLC

In WebFOCUS since 2001
October 24, 2012, 02:23 PM
Joey Sandoval
Yes, this works great - thank you. But do you think it is possible to get the same results without a hold table? I was thinking there might be a multi-verb solution as well.




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


October 24, 2012, 02:38 PM
rfbowley
FOCUS works on one Row at a time, and the only varient to that is the ability to compare the current row with the previous one with LAST. Hold files give us the ability aggregate like this without dedicating vast amounts of resources to long term storage.


Robert F. Bowley Jr.
Owner
TaRa Solutions, LLC

In WebFOCUS since 2001
October 29, 2012, 01:39 AM
StuBouyer
Not sure if you are trying to always get the lowest sales value but this does that:
  
DEFINE FILE CAR
COMMISSION/D12.2 = SALES*.035;
END

TABLE FILE CAR
SUM 
COMPUTE LOW_SALES_THRESHOLD_PCT/P8.2 = IF MIN.SALES LE 40000 THEN MIN.SALES/40000 ELSE 1; NOPRINT
BY COUNTRY 
SUM 
DEALER_COST
RETAIL_COST
SALES
COMMISSION
COMPUTE C_COMMISSION/P8.2 = COMMISSION * LOW_SALES_THRESHOLD_PCT;
COMPUTE SALES_THRESHOLD_PCT/P8.2 = IF SALES LE 40000 THEN SALES/40000 ELSE 1; NOPRINT
BY COUNTRY
BY CAR

ON COUNTRY SUBTOTAL AS ''
ON COUNTRY SUBFOOT 
" "

ON TABLE SET PAGE-NUM NOLEAD
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     INCLUDE = endeflt,
$
ENDSTYLE
END


You can have lots of fun with Multi-verbs, but the sometimes get weird when JOINS are involved.

Cheers

Stuart


WebFOCUS 8.2.03 (8.2.06 in testing)
November 05, 2012, 04:24 PM
Joey Sandoval
Thank you StuBouyer. Your example was the other solution I was looking for!




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