Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

10/07/2024 09:56 Building Advanced Formula Data Actions

Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Building Advanced Formula Data


Planning in Stories

Actions
Configuring Data Actions

Objectives
Configuring Data Actions
After completing this lesson, you will be able to:
57 mins
Build advanced formula data actions
Building Advanced Formula Data
Actions
59 mins

Advanced Formula Data Actions Introduction


Creating Dynamic Data Actions and
Planning requires various types of calculations. To perform these calculations, you can use
Tables
advanced
5 mins data actions (formulas).

Here are some key points regarding advanced formulas:


Configuring Multi Actions
Use Cases:
20 mins
Advanced formulas provide a mechanism for custom calculation logic
Managing Data
Driver-based Action Performance
formulas: Rev = Price x Qty
10Depreciation
mins calculation
Populate opening balances for headcounts
Quiz Mark-ups | Mark-downs

Schedule or run on an ad-hoc basis

Maintenance:
Allocating Planning Data
The script editor provides context help and code completion
Validation and trace mode in the script editor

Features:
Translating Currencies for Planning
The visual editor provides a graphical wizard to define calculation logic
The statements are represented by boxes, which can be further configured with special
Forecasting and Simulating Planning
dialogs
Data The graphical representations give users a clear logic flow

Coordinating and Controlling


Processes

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 1/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Note

Advanced data actions are used to perform calculations that are stored in the database. If
there's a need to perform calculations that aren't stored in the database, there are several
options:
Data table formulas
Story-based calculated measures
Model-based calculated measures

Advanced Data Actions

Create Calculations with the Visual Editor


Use the visual tool to drag and drop graphic elements in a flow diagram to create advanced
formulas. The general process flow for creating advanced formulas is:

1. Specify the context


2. Define and use a variable if needed
3. Set the configuration options: Calendar, Signflip, Unbooked
4. Formula options:

Calculation
Repeat
Condition
Delete
Comments

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 2/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Advanced Formula
Advanced formula actions allow you to design formulas for calculations to apply to the source
data. The results are written to specified scopes in the planning model.
Unlike dimension formulas, which perform the calculation in real-time "on the fly", the advanced
formulas data action stores the result of the calculation in the SAP Analytics Cloud database.
And as with dimension formulas, parameters can be used in the advanced formula data action.

Recent Enhancements for Advanced Data Actions


Support AND/OR for IF condition: Complex and detailed condition expressions are possible
with shorter scripts, which means better execution performance time as well as better
readability.
Keyword "BREAK" that stops a loop if a specific condition is fulfilled: Support an immediate
stop of FOREACH loop with IF condition or others. For example, stopping the depreciation loop
with date dimension is possible if the residual book value reaches zero value or the iteration
number reaches and the same as the useful life. You don't need to loop for an entire date scope
resulting in better execution performance.

Load pre-aggregated value as calculation scope: Minimize the dataset size of calculation scope
for non-calculation related dimensions.
Pop-up dialog-box that shows the calculation scope: Estimate the calculation scope at design
time and optimize the script for better execution performance.

Visual Editor Compared to the Script Editor


The visual editor can be used for simpler calculations. It generates the script automatically.

The script editor is used for more complex programming.

You can hover on a dimension in the data line to see what members are included in the scope of
the Calculation.

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 3/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Ways to Design Advanced Formulas


There are two different ways to design advanced formulas – using the visual tool and writing
scripts.

You can build your own logic in the visual editor and then view the generated code in the script
editor.

Summary: Visual Editor and Script Editor

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 4/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Learning
Visual Editor Script Editor

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality


Target for Enterprise
professional modeling users,/such
Planning as …
Buildin
Target business users
IT specialists

No coding skills required Requires basic coding knowledge

Created by dragging and dropping


Created by writing scripts
graphic elements

Can be switched to script Can be switched back to the visual editor

Context Membersets

Use Membersets to Restrict the Data Region


Membersets are used to restrict the data region for the calculation.

Typical use cases:

MEMBERSET [d/ORGANIZATION].[p/REGION] ="ASIA": Set the scope of the Organization


dimension's Region property to ASIA.
MEMBERSET [d/FLOW] = ("F_TEMP", "F_NONE"): Set the scope of the Flow dimension to the
F_TEMP and F_NONE members.
MEMBERSET [d/CURRENCY] = [d/ORGANIZATION].[p/CURRENCY]: Set the Currency
dimension's scope to the value of the Organization dimension's currency property.
CONFIG.HIERARCHY = [d/ENTITY].[h/H1] MEMBERSET [d/ENTITY] =
BASEMEMBER([d/ENTITY], "World"): Return all base members of the member "World" in
hierarchy H1 and set these base members as the member scope of the Entity dimension.
MEMBERSET [d/DATE] ="202201" TO "202212": Set the scope of the Date dimension from
202201 to 202212.

Memberset is used to determine the context, that is the Point of View or the Scope.

In the preceding example, see the explanations for the script:

MEMBERSET [d/Date] = (BASEMEMBER([d/Date].[h/YQM], %YearMonth%))


BASEMEMBER refers to leaf members for calendar year in this example.

The time hierarchy is set to the Calendar Year, therefore YQM is the hierarchy ID.

% denotes variables: for example %YearMonth% refers to the prompt/variable for time.

Result: If you select 2021, the system will include all months of 2021 in the calculation.

MEMBERSET [d/Cost_Center] = (BASEMEMBER([d/Cost_Center].[h/H1],


"All_Cost_Centers"))
https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 5/15
10/07/2024 09:56 Building Advanced Formula Data Actions

The H1 hierarchy for the cost center dimension has been selected.
Learning
All_Cost_Centers is the id of the top node/parent.
Result, if the user selects hierarchy node Canada, only Canadian cost centers will be included in
/ Browse / the
Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…
calculation.

Advanced Formula Memberset Example


The following script will only run for PC1 & PC2 (that is, only PC1 & PC2 are scoped).

In the preceding example, January data is being copied to February with an uplift:

DATA([d/Date] = %TargetMonthYr%) = RESULTLOOKUP([d/Date]=PREVIOUS(1)) *


%UpLift%

In this example, %TargetMonthYr% is the receiver or target that is dynamically selected by the
planner.
RESULTLOOKUP([d/Date]=PREVIOUS(1)) dynamically reads the previous month (or period) as
compared to the %TargetMonthYr% selection.
%UpLift% is the variable for the uplift provided by the planner. Example: 1.25.

Use the Visual Editor to Create an Advanced


Formula
Business Scenario
You are a member of the planning team at ABC Corporation and you are responsible for creating
and configuring data actions.

Before Jen can run the data action to perform the calculation, you must use the visual editor to
create a data action that calculates labor. Since labor rates are in the HR model, you will use the
link command to look-up the labor rates and calculate labor.

What skills will you develop in this practice exercise?


In this practice exercise, you will:

Create the parameters (prompts)


Create the advanced formula action for labor
https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 6/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Run the data action from the story to calculate labor


Learning

EXERCISE
/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Start Exercise

Variables
Variables in advanced formulas can be used to store data temporarily while the script is running, to
avoid calculating the value repeatedly. This is the traditional concept referred to as a Local
Variable. or Virtual Variable Member. The virtual variable member will be stored independently
and cannot be added to a dimension like a real dimension member. After defining a variable
member for a certain dimension, you can use the variable member to store values only for that
specific dimension.

Key Points:

Write this definition after the configuration settings and before all the instructions.
Create a new name for a virtual variable member. Make sure, in the variable member definition,
it always starts with the prefix "#".
Dimension Name is mandatory and must be an existing dimension in the current data action
model. The version dimension is not supported. Measures are supported, for example:
VARIABLEMEMBER #Total_Revenue OF [d/Measures]
A virtual variable member can only be used in DATA and RESULTLOOKUP functions. When
inputting "#" in DATA() or RESULTLOOKUP(), a list of all available virtual members will be shown.

In the following example of advanced logic virtual variables, you can see that:

SumOfProducts is the temporary account for total sales revenue.


Since the total sales are over 1000 (1500), the system calculates other income of 1500 x -.01 for
each product.

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 7/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Configuration Options
Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…
Configuration Options

Fiscal Year: This configuration governs the time hierarchy used in the advanced formulas.
This setting affects the result of time/date commands, such as FIRST and LAST.It controls
which period is selected.

Account Sign Flip: If this option is turned on, all calculations consider the sign value (debit
or credit) of each account according to the account type (LEQ, AST, INC, and EXP).

Unbooked Data: Unbooked data refers to cells with empty values. If turned on, all empty
cells in the source data to be copied will be treated as cells with zeroes.

Advanced Formula - Time Hierarchy


Time can be interpreted as YQM: Year | Quarter | Month or as FYQP: Fiscal Year | Quarter | Period.

This configuration governs the time hierarchy of the script. If this configuration is not defined, the
default time hierarchy from the model is used.

Advanced Formula - Sign Flip


In advanced formulas, all data is calculated in absolute value by default, regardless of the account
type. This is important when working with the Account dimension, where certain accounts will have
positive values while others will have negative values. If you want to calculate with the existing
sign-flipping rules of Account dimensions, then enter
CONFIG.FLIPPING_SIGN_ACCORDING_ACCTYPE=ON at the beginning of your script.

In the following example, the memberset command is selecting data for revenue and cost and
then writing the result to retained earnings. If the sign flip setting is ON, the correct value (40) is
written to retained earnings.

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 8/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Advanced Formula - Unbooked Data


In the following example, January data for profit centers PC1/2/3 is being copied to February. By
using the Unbooked setting, the existing 500 value for PC4 can either be retained or set to zero (to
match the source).

Syntax and Auto Complete

Auto Complete
As you type, a hint list shows all available functions that match the text you've typed. A short help
text description is available for each function. You can use Ctrl+Space to choose from a list of
values that are valid for that location in the formula, or type [d/ for a list of valid dimensions and
properties to use in the formula.

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-a… 9/15
10/07/2024 09:56 Building Advanced Formula Data Actions

There are also formula templates for common calculations. If you select a formula from the hint
Learning
list, a template is automatically entered in the formula entry bar.

Examples of how to use auto-complete:


/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…
Type M to access the command that start with the letter M.
Type [d/ to access the model dimensions.
Press Ctrl+Space to access members and parameters.

Script Syntax
[ ]: Dimensions, properties, hierarchies are enclosed in square brackets
d: Dimension. Example: [d/Cost_Center]
p: Property. Example: [d/Account].[p/ElimTarget]
h: Hierarchy. Example: [d/Cost_Center].[h/H1], "All_Cost_Centers"))
%: Variables. Example: % YearMonth%
#: Unassigned. Example: since labor hours aren’t currency related, currency is
unassigned:RESULTLOOKUP([d/Account] = "LHours", [d/Currency] = "#")
" ": Double quotes are required when specifying dimension members.
/: Comments

Note

In an advanced formulas step, you can repeat a group of statements a specified number of
times, using the FOR keyword. Employing a BREAK statement inside a FOR loop will allow
you to stop the loop when the given condition is met, offering more flexibility.

Note

In the Show option in the Script tab, you can turn Auto Complete off.

For more syntax options, to the reference guide: Advanced Formulas Reference Guide

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-… 10/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Formula Options
Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…
Formula Options
When you create an advanced formula, you have 5 options.

1. Calculation will create an equation such as Target = Expression


A calculation is divided into two parts: Target and Source:
Target is the data range to which you plan to write data.
Source is the data involved in the calculation.

2. Delete will prompt for a filter upon which to identify which cost center to delete, for example.

3. Repeat (loop) will prompt for a dimension to loop over, and then you can add a calculation, for
example.

For example, calculate revenue amount with a 10% increase over the previous month:

Code snippet Copy code

1
2 MEMBERSET [d/Date] = (BASEMEMBER([d/Date].[h/YQM], "[2024]"))
3 MEMBERSET [d/Measures] = ("Amount")
4 MEMBERSET [d/Account] = ("Revenue")
5 FOREACH [d/Date]

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-… 11/15
10/07/2024 09:56 Building Advanced Formula Data Actions

6 Data() = ResultLookup([d/Date]=PREVIOUS(1)) * 1.1


Learning 7 ENDFOR

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…
4. Comment creates an input field for explanations.

5. Condition will prompt for a filter upon which to create the if statement, and then you can add a
calculation.

For example, if the company = US, then copy prior year data to the current year data +10%.

Code snippet Copy code

1
2 MEMBERSET [d/Date] = (BASEMEMBER([d/Date].[h/YQM], "[2024]"))
3 MEMBERSET [d/Measures] = ("Amount")
4 MEMBERSET [d/Account] = ("Revenue")
5 IF [d/Company] = "US" THEN
6 DATA() = RESULTLOOKUP([d/Date] = Previous(12)) * 1.1
7 ENDIF

In the previous examples, you can see how the system creates formulas depending on which
option you pick. Each one generates code that you can view in the script dialog. In the following
example, you can see an example of a Calculate Labor formula in the Visual Editor.

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-… 12/15
10/07/2024 09:56 Building Advanced Formula Data Actions

Learning

/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Editing Options
There are four editing options, when you hover over the formula:

1. Duplicate
2. Annotate
3. Comment out
4. Delete

Using Scripts to Write Advanced Formulas


When using script to write advanced formulas, keep the following in mind:

1. Each line of instruction inherits the calculation results of previous lines of instructions.
2. Advanced formulas perform all calculations only with leaf-level members that don’t have any
account formulas defined.
3. In a RESULTLOOKUP function, the function considers the most detailed values in the dataset,
even if the formula doesn't specify them. For example, consider the following record set:

Account Product Entity Date Value

Sparkling 210 (aggregate of all


Quantity Region Dec.2018
Water countries)

Sparkling
Quantity Germany Dec.2018 50
Water

Sparkling
Quantity France Dec.2018 70
Water

Sparkling
Quantity UK Dec.2018 90
Water

You write a formula to add 20 to the Quantity Values for December 2018 and write the new
values to January 2019:

MEMBERSET[d/Product]="Sparkling Water" MEMBERSET[d/Account]="Quantity"


DATA([d/Date]="Jan.2019")=RESULTLOOKUP([d/Date]="Dec.2018")+20

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-… 13/15
10/07/2024 09:56 Building Advanced Formula Data Actions

The final result will add 20 to each detailed Entity value, not to the aggregated Region value:
Learning

Account Product Entity Date Value


/ Browse / Learning Journeys / Leveraging SAP Analytics Cloud Functionality for Enterprise Planning / Buildin…

Sparkling 270 (aggregate of all


Quantity Region Jan.2019
Water countries)

Sparkling
Quantity Germany Jan.2019 70
Water

Sparkling
Quantity France Jan.2019 90
Water

Sparkling
Quantity UK Jan.2019 110
Water

4. A null value is treated as a non-existent value, while 0 is treated as an actual number. If the
RESULTLOOKUP function returns a null value, advanced formulas do nothing.
5. Advanced formulas basically work with the fact record-set of the model. If you don't specify
other dimension information and members via the MEMBERSET definition, the advanced
formulas will take all members from the dimensions in the model.

Note

In an advanced formulas step, you can repeat a group of statements a specified number of
times, using the FOR keyword. Employing a BREAK statement inside a FOR loop will allow
you to stop the loop when the given condition is met, offering more flexibility.

Use the Visual and Script Editors to Create the


Advanced Formula Action

Scenario: Calculating Labor and Benefit with an Advanced


Data Action
As part of the 2025 Forecast Income Statement for ABC Corporation, Jen must calculate the labor
and benefits.

Site Information Quick Links About SAP Support and Contact

Privacy Download Catalog (CSV, Company Information Share Feedback


JSON, XLSX, XML)
Terms of Use Copyright Get Support

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-… 14/15
10/07/2024 09:56 Building Advanced Formula Data Actions
Legal Disclosure SAP Developer Center Trademark Frequently Asked
Learning Questions
Cookie Preferences SAP Community Worldwide Directory

Do not share/sell
/ Browse my
/ Learning SAP Learning
Journeys Hub SAP Analytics
/ Leveraging Careers
Cloud Functionality for Enterprise Planning / Buildin…
personal information (US
Learners only) SAP Training Shop News and Press

Newsletter

Find us on:

Business Scenario
You are a member of the planning team at ABC Corporation and you are responsible for creating
and configuring data actions.

Before Jen can run the data action, you must create and test an advanced formula data action
using the visual editor as well as the script editor. The benefits rate will be entered when Jen runs
the data action.

What skills will you develop in this practice exercise?


In this practice exercise, you will:

Create the advanced formula to calculate benefits


Run the data action from the story

EXERCISE

Start Exercise

Next lesson

Was this lesson helpful? Yes No

https://learning.sap.com/learning-journeys/leveraging-sap-analytics-cloud-functionality-for-enterprise-planning/building-advanced-formula-data-… 15/15

You might also like