Thursday 13 July 2017

Successful implementation of Cumulative Sum in SAP HANA

A cumulative sum is a sequence of partial sums of a given sequence. For example, the cumulative sums of the sequence {a, b, c, ...} are a, a+b, a+b+c, .....Cumulative sums.

Cumulative Sum: Cumulative sums, or running totals, are used to display the total sum of data as it grows with time (or any other series or progression). This lets you view the total contribution so far of a given measure against time.

If you’re a frequent user of the SUM function, you may occasionally want to take the cumulative SUM of a value across a table. For example, if you have a table that outlines product sales by month for an entire year, you may want to insert a cumulative SUM column that shows year-to-date sales at the end of each month.

This can be easily accomplished using relative and absolute cell references combined with the SUM function. Let’s take a look at how it works.

Following are the steps to implement Cumulative Sum in SAP HANA

Step 1: Create a table and Insert the data into the table.

Created “CUMMULATIVE_SUM” table using SQL Console.

SAP HANA studio, calculation views

Insert the data into “CUMMULATIVE_SUM” table

SAP HANA studio, calculation views

SAP HANA studio, calculation views

Step 2 : Create Script based calculation view with the name “CLV_CUMMULATIVE_SUM_SCRIPT_BASED”

SAP HANA studio, calculation views

Click on Finish button

SAP HANA studio, calculation views

/********* Begin Procedure Script ************/  /********* Begin Procedure Script ************/

BEGIN 
  var_out =SELECT ID,NAME,MARKS,SUM(MARKS) OVER (ORDER BY ID) AS

CUMMULATIVE_SUM FROM “KRISHNA_REDDY”.”CUMMULATIVE_SUM” ORDER BY ID;

END
/********* End Procedure Script ************/

Save and Validate the view then

Save and Activate the View

Step 3: Check the output

click on Data preview button to see the output

SAP HANA studio, calculation views

No comments:

Post a Comment