Skip to content
NextLytics
Megamenü_2023_Über-uns

Shaping Business Intelligence

Whether clever add-on products for SAP BI, development of meaningful dashboards or implementation of AI-based applications - we shape the future of Business Intelligence together with you. 

Megamenü_2023_Über-uns_1

About us

As a partner with deep process know-how, knowledge of the latest SAP technologies as well as high social competence and many years of project experience, we shape the future of Business Intelligence in your company too.

Megamenü_2023_Methodik

Our Methodology

The mixture of classic waterfall model and agile methodology guarantees our projects a high level of efficiency and satisfaction on both sides. Learn more about our project approach.

Products
Megamenü_2023_NextTables

NextTables

Edit data in SAP BW out of the box: NextTables makes editing tables easier, faster and more intuitive, whether you use SAP BW on HANA, SAP S/4HANA or SAP BW 4/HANA.

Megamenü_2023_Connector

NextLytics Connectors

The increasing automation of processes requires the connectivity of IT systems. NextLytics Connectors allow you to connect your SAP ecosystem with various open-source technologies.

IT-Services
Megamenü_2023_Data-Science

Data Science & Engineering

Ready for the future? As a strong partner, we will support you in the design, implementation and optimization of your AI application.

Megamenü_2023_Planning

SAP Planning

We design new planning applications using SAP BPC Embedded, IP or SAC Planning which create added value for your company.

Megamenü_2023_Dashboarding

Dashboarding

We help you with our expertise to create meaningful dashboards based on Tableau, Power BI, SAP Analytics Cloud or SAP Lumira. 

Megamenü_2023_Data-Warehouse-1

SAP Data Warehouse

Are you planning a migration to SAP HANA? We show you the challenges and which advantages a migration provides.

Business Analytics
Megamenü_2023_Procurement

Procurement Analytics

Transparent and valid figures are important, especially in companies with a decentralized structure. SAP Procurement Analytics allows you to evaluate SAP ERP data in SAP BI.

Megamenü_2023_Reporting

SAP HR Reporting & Analytics

With our standard model for reporting from SAP HCM with SAP BW, you accelerate business activities and make data from various systems available centrally and validly.

Megamenü_2023_Dataquality

Data Quality Management

In times of Big Data and IoT, maintaining high data quality is of the utmost importance. With our Data Quality Management (DQM) solution, you always keep the overview.

Career
Megamenü_2023_Karriere-2b

Working at NextLytics

If you would like to work with pleasure and don't want to miss out on your professional and personal development, we are the right choice for you!

Megamenü_2023_Karriere-1

Senior

Time for a change? Take your next professional step and work with us to shape innovation and growth in an exciting business environment!

Megamenü_2023_Karriere-5

Junior

Enough of grey theory - time to get to know the colourful reality! Start your working life with us and enjoy your work with interesting projects.

Megamenü_2023_Karriere-4-1

Students

You don't just want to study theory, but also want to experience it in practice? Check out theory and practice with us and experience where the differences are made.

Megamenü_2023_Karriere-3

Jobs

You can find all open vacancies here. Look around and submit your application - we look forward to it! If there is no matching position, please send us your unsolicited application.

Blog
NextLytics Newsletter Teaser
Sign up now for our monthly newsletter!
Sign up for newsletter
 

Handling account & key figure model in SAP HANA SQLScript & CalcView

In this blog post, we look at several variants for transforming or pivoting/unpivoting a dataset between the account model and the key figure model. For this purpose, we will first illustrate and explain the terms of the account model and key figure model, respectively, and then show the possibilities for transformation that SAP HANA offers.

The inclined SAP Business Warehouse (BW) user will already be familiar with the terms account model and key figure model.

table_account model

Account Model

The table above visualizes a data modeling according to the account model.

It contains a column with the name of the key figure and a second column with the corresponding value. Regardless of the number of key figures, only two columns are used here.

table_key figure model

Key Figure Model

The table above, on the other hand, shows the key figure model.

Thus, a separate column is modeled for each key figure. The name of the key figure is also the name of the column and the values of the column contain the respective values of the key figure.

If there is no value for the key figure of a data record, it is filled with a default value, e.g. null or 0.

There are a number of advantages and disadvantages resulting from these approaches:

  • No unnecessary values are saved in the account model (null or 0 in the key figure model).
  • A new key figure can be modeled in the account model without changing the data model.
  • The key figure model facilitates the analysis and is therefore preferably used in the frontend/reporting - therefore a transformation from account model to key figure model may have to be done in the backend
  • For row-based tables, the performance of the account model is stronger

Historically, the use of both of these models was essential, as modeling according to the account model enabled better performance of the BW system, but the key figure model was (and still is) essential for reporting. With the introduction of the column-based architecture of the tables in the SAP HANA database, the use of the account model is no longer performance-relevant, but may still be justified for architectural reasons.


Performance boost with SQLScript -
Download whitepaper now! 

Neuer Call-to-Action


From account model to key figure model (pivot)

Now let's look at a scenario where we want to transform a data model based on the account principle into the key figure model in the HANA context. Architecturally, we have the choice of enabling this transformation either graphically in a Calculation View, or implementing it as part of a script-based HANA object, such as a Table Function, using SQLScript.

In the SQLScript-based approach, a CASE-WHEN statement is used for each key figure to be modeled:

-- Account Model to Key Figure Model
SELECT
ID,
SUM (CASE
WHEN "FIELD" = 'SALES'
THEN "VALUE"
ELSE 0
END) as "SALES",
SUM (CASE
WHEN "FIELD" = 'QUANTITY'
THEN "VALUE"
ELSE 0
END) as "QUANTITY",
SUM (CASE
WHEN "FIELD" = 'ORDERS'
THEN "VALUE"
ELSE 0
END) as "ORDERS"
FROM
"IRN"."ACCOUNTMODEL"
GROUP BY
ID
ORDER BY
ID;

Since apart from the CASE-WHEN framework no extraordinary SQL logic is required here, the same functionality can also be implemented using a Calculation View. Calculated Columns are used for this purpose. Each CASE-WHEN statement is equivalent to a Calculated Column:

picture_pivot_calculation view

Pivot with Calculation View

From key figure model to account model (Unpivot)

Here as well, we can use either a Calculation View or SQLScript.

For the graphical solution, we first create a Projection Node for each key figure and then connect it to a Union Node. Afterwards we edit the Union Node by:

  • Removing all mappings of the key figures that may already have been entered automatically;
  • Using the "+" sign in the "Target" area of the Union Node we create two custom target fields - one for the field names and one for the field values;
  • Right click on the custom field for the field labels => Manage Mappings and map the projection nodes with one constant value each to the field for the field labels;
  • Map one key figure from each projection node to the field for the field values (according to the previously defined Constant Value to projection node pairs).

picture_unpivot_calculation view

Unpivot with Calculation View

Analogously, this principle can also be applied via SQLScript. A subselect is written for each key figure and these subselects are connected by UNION ALL:

-- UNION ALL: Key Figure Model to Account Model

SELECT
ID, 'SALES' as "FIELD", "SALES" as "VALUE"
FROM "IRN"."KPIMODEL"

UNION ALL

SELECT
ID, 'QUANTITY' as "FIELD", "QUANTITY" as "VALUE"
FROM "IRN"."KPIMODEL"

UNION ALL

SELECT
ID, 'ORDERS' as "FIELD", "ORDERS" as "VALUE"
FROM "IRN"."KPIMODEL";

Alternatively, HANA also offers the possibility of combining two built-in functions - MAP() and SERIES_GENERATE_INTEGER(). The latter automatically generates a table containing a series of numbers - for us the generated column "ELEMENT_NUMBER" is interesting. The MAP() function allows us to assign a series of initial values to a target value each. So we generate a number series using SERIES_GENERATE_INTEGER() that corresponds to the number of our key figures and form a cross join with the table that contains our key figure based data model. We then use MAP() to correctly populate the two fields for the field label and field value in the SELECT.

-- MAP(): Key Figure Model to Account Model

SELECT

ID,
MAP(element_number,
1, 'SALES',
2, 'QUANTITY',
3, 'ORDERS')
as "FIELD",
MAP(element_number,
1, "SALES",
2, "QUANTITY",
3, "ORDERS")
as "VALUE"
FROM "IRN"."KPIMODEL"
CROSS JOIN SERIES_GENERATE_INTEGER(1,1,4);

Do you have questions about this or other topics? Are you trying to build up the necessary know-how in your department or do you need support with a specific question? We will be happy to help you. Request a non-binding consulting offer today.

Learn more about  SAP HANA SQLScript

avatar

Irvin

Irvin has worked with HANA Native and Datasphere since 2019. He can primarily draw on experience as a consultant and in development on the XSA platform using SQLScript. In his spare time, he is passionate about playing basketball and is also a big NBA fan.

Got a question about this blog?
Ask Irvin

Blog - NextLytics AG 

Welcome to our blog. In this section we regularly report on news and background information on topics such as SAP Business Intelligence (BI), SAP Dashboarding with Lumira Designer or SAP Analytics Cloud, Machine Learning with SAP BW, Data Science and Planning with SAP Business Planning and Consolidation (BPC), SAP Integrated Planning (IP) and SAC Planning and much more.

Subscribe to our newsletter

Recent Posts