Skip to Content

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).

Region PRODUCT MONTH Header 4 R1 P1 JAN 100 R1 P1 JAN 200 R2 P2 JAN 300 R2 P1 FEB 100 R3 P2 MAR 100

My output should be

Region sales 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;

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jun 08, 2015 at 10:48 AM

    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;

    Add comment
    10|10000 characters needed characters exceeded