Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Sales percentage calculation

Hi All,

I have table with data Region, product,month, sales amount with data in HANA DB.I want to calculate the region wise sales percentage on the total sales in hana studio.(Some thing like % GT in BW).

RegionPRODUCTMONTHHeader 4
R1P1JAN100
R1P1JAN200
R2P2JAN300
R2P1FEB100
R3P2MAR100

My output should be

Regionsales percentage
R1=300/800 => 37.5%
R2=400/800 => 50%
R3=100/800 => 12.5%

i started doing using procedure but could not arrive to get final output. Any suggestions / ways to get % sales of region.

BEGIN

DECLARE V_SALES DOUBLE;

VAR = SELECT SUM(SALES_AMOUNT) FROM "JOSE_HANA"."SALES";

OUTPUT_TABLE = SELECT "REGION_ID", ( SUM(SALES_AMOUNT) / VAR * 100)  AS SALES_PERC

FROM "JOSE_HANA"."SALES"

GROUP BY "REGION_ID"

ORDER BY SUM(SALES_AMOUNT) DESC;

END;

Former Member
Former Member replied

Try the below mentioned code :

BEGIN

DECLARE V_SALES DOUBLE;

DECLARE VAL DOUBLE;

SELECT SUM(NETVAL) INTO VAL FROM "TEST"."SALES";

OUTPUT_TABLE = SELECT "REGION", ( SUM(NETVAL) / VAL * 100)  AS SALES_PERC

FROM "TEST"."SALES"

GROUP BY "REGION"

ORDER BY SUM(NETVAL) DESC;

END;

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question