As part of this blog, I would like to introduce you to the new variable derivation feature in Analytic model within SAP Datasphere for currency conversion measures, as mentioned in the SAP Help documentation.
Before we start, you may be wondering what is variable derivation and why do we need this?
For example, let say we have a sales report where users would like to see Net Amount in the currency of their choice and it is preferred by them to choose a country to fetch the respective currency using a flexible lookup logic instead of them knowing the currency codes. For building the flexible lookup logic, an independent lookup entity having country-currency relationship can be used. Also, further in the lookup entity, extra features like language-dependent value help for countries can be added later, as well.
To realize the above scenario, 4 main components will be needed.
Fig a: User Workflow
The high-level user workflow would be as shown above and it provides the following advantages:
Obviously, a country->currency lookup is very simplistic, but lookups can be lot more complex. Some scenarios are described below:
At this point, only source variables and reference date variables can be derived, but SAP has some interesting enhancements in the works that will over time boost the power of variable derivations even more. Our vision is to extend the variable derivation for the other variable types, namely Restricted Measure & Filter variables, as well. And, further, introduce the same concept for Calculated Measures as well.
Please note that here we are just sharing the vision, hence not committing or liable to any new feature release.
In the next sections, we will look at the inner workings of the country->currency lookup example.
For Currency conversion, please make sure you have currency conversion tables available within your space as mentioned in the SAP Help Documentation.
In our scenario, we will be using the derived source variables within Currency Conversion measures in Analytic Model to get the derived value for Target currency and also, for Reference date from two separate lookup entities, as shown below.
Fig b: Currency Conversion Measure
These values will be derived using a source variable in the Analytic Model where we have an option to use the Derive value, as shown below.
Fig c: Source Variable - Derive Value
So, from above, we can categorize the whole process within Analytic Model into below high-level steps.
In this step, we will create two lookup entities - one for translating country to currency and another one for translating a human-readable time representation (today, yesterday, same day 5 years ago etc.) into a proper date.
1.1 First lookup entity, MCT_Lookup_Currency_From_Country, is a simple view containing 2 columns – Country and Currency.It stores data for the country->currency relationship like USD for US.
Fig d: First Lookup Entity - MCT_Lookup_Currency_From_Country
Further, it has an input parameter Country for filtering the data on the Country column, as shown below.
Fig e: First Lookup Entity Country Filter
The source of this view is a simple table MCT Country, as shown below.
Fig f: First Lookup Entity Source
1.2 Second look up entity, Date_Lookup_Entity, has an input parameter Date selection and is having the SQL view Date_Lookup as its source, as shown below.
Fig g: Second Lookup Entity - Date_Lookup_Entity
And this input parameter Date selection is further used to filter the ID column, as shown below.
Fig h: Second Lookup Entity Date Filter
Further, source SQL view Date_Lookup uses SQL Date and Time functions like CURRENT_DATE etc. to create a view with the date and time related data, as shown below.
Fig i: Second Lookup Entity SQL View
Moreover, this SQL view is created on the text table Date_Texts which has below simple structure and text data inserted into it using Data editor, as shown below.
Fig j: Second Lookup Entity Source table
In this step, we will create the variables to prompt the users for a country as well as for a readable date placeholder (like Today, Yesterday, Start of Month etc.).
2.1 Once the lookup entities are defined, please go to the respective Analytic Model and define the source variable, COUNTRY, as shown below.
Fig k: Source variable Country
2.2 Then, create another source variable, DATE_SELECTION, as shown below.
Fig l: Source variable Date
Now, we come to the core of this blog - the variable derivation. Here, we create two source variables and configure them such that they derive their values by help of the lookup entity and the prompt value provided by the end-user
3.1 Next, create derived source variables, CURRENCY_REF_DATE, as shown below.
Fig m: Derived Variable - CURRENCY_REF_DATE
Here, for the lookup entity use the view Date_Lookup_Entity, created in step 1, and result column as Date.
Then map the input parameter, Date selection, of the lookup entity to the source variable, DATE_SELECTION, created in the previous step, as shown below.
Fig n: Derived Variable Lookup Entity Parameter Mapping
Note that we could also create a new variable on the fly rather than reusing the variable DATE_SELECTION that we create earlier.
3.2 Next, create the source variable, TARGET_CURRENCY_FROM_LOOKUP, to derive value for target currency, as shown below.
Fig o: Derived Variable - TARGET_CURRENCY_FROM_LOOKUP
Here, for lookup entity use the view MCT_Lookup_Currency_From_Country, created in step 1, and result column as Currency.
Then map the input parameter, Country, of the lookup entity to the source variable, COUNTRY, created in the previous step, as shown below.
Fig p: Derived Variable Lookup Entity Parameter Mapping
By now, it's time to make use of our derived variable in a currency conversion measure.
4.1 First create a Currency Conversion measure, as shown below.
Fig q: Currency Conversion Measure
5.2 Next, in the measure definition for Target Currency and Reference Date choose the derived source variables created in previous step, as shown below.
Fig r: Choose Derived Variables
Once done save and deploy the Analytic Model.
So, we're done building things and now, let's test things.
5.1 As a final step, please go to the Analytic Model Preview and enter the value for Input Parameters Country and Date selection as US and TODAY, respectively.
Fig s: Variable Screen
This will pass these values to the lookup entity and fetch the Target Currency and Reference Date to be used within the currency conversion measure to provide us the desired result.
Fig t: Derived Variable Lookup Entity Parameter Mapping
In this blog, I showed you how to use the currency conversion measures with the derived source variable.
Please make use of this cool new feature and let us know your valuable feedback.
Best wishes,
Jai Gupta
Find more information and related blog posts on the topic page for SAP Datasphere .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
20 | |
11 | |
8 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |