cancel
Showing results for 
Search instead for 
Did you mean: 

Sales percentage calculation

joseph_reddy88
Participant
0 Kudos

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;

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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;

joseph_reddy88
Participant
0 Kudos

Thank you very much. Its working.

Answers (0)