How to Create and Use Formula Variables in SAP BW/4HANA Queries with Examples
SAP BW/4HANA is a data warehouse solution that allows you to analyze and report on large volumes of data from various sources. One of the features of SAP BW/4HANA is the ability to create and use variables in queries. Variables are placeholders that can be replaced by values at query runtime, depending on the user input or system settings. Variables can help you to make your queries more flexible, dynamic and user-friendly.
In this blog post, we will explain how to create and use formula variables in SAP BW/4HANA queries. Formula variables are variables that are replaced by the result of a formula. The formula can contain arithmetic operations, functions, constants, or other variables. You can use formula variables to perform calculations or transformations on the data.
We will also show you some examples of how to create and use formula variables in different scenarios, such as calculating the sales growth rate, displaying the current date or fiscal year, or using the current member of a time characteristic.
Creating Formula Variables in SAP BW/4HANA Queries
To create and use formula variables in queries in SAP BW/4HANA, you need to use the Query Designer tool. The Query Designer allows you to drag and drop InfoObjects or reusable query elements from the InfoProvider screen to the query rows and columns. You can also edit the properties of the variables using the Properties pane.
Here are the steps to create and use formula variables in queries in SAP BW/4HANA:
- Open the Query Designer and select the InfoProvider that you want to use for your query.
- Click on Variables on the toolbar to open the Variables screen.
- Click on Create Variable to create a new variable, or select an existing variable and click on Edit Variable to modify it.
- In the Create Variable or Edit Variable dialog box, enter a name and a description for the variable.
- Select Formula as the variable type from the drop-down list.
- Select Replacement Path as the processing type from the drop-down list.
- In the Replacement Path tab page, select Formula as the replace variable with option.
- Enter a formula for the variable in the Formula field. You can use arithmetic operators, functions, constants, or other variables in your formula. You can also use the input help dialog to select predefined functions or variables.
- Click on OK to save the variable.
Using Formula Variables in SAP BW/4HANA Queries
After creating a formula variable, you can use it in your query by dragging and dropping it from the Variables screen to the query rows or columns. You can also use it as a filter or a formula element.
Here are some examples of how to use formula variables in SAP BW/4HANA queries:
- To calculate the sales growth rate using a formula variable called SALES_GROWTH_VAR that is replaced by a formula that divides the difference between sales of current year and previous year by sales of previous year, drag and drop SALES_GROWTH_VAR from the Variables screen to the Calculated Key Figures screen. In the Properties pane, enter a description for the calculated key figure. For example, if you want to calculate the sales growth rate using SALES_GROWTH_VAR that is replaced by a formula like this:
1 |
(Sales[Current Year] - Sales[Previous Year]) / Sales[Previous Year] |
You can drag and drop SALES_GROWTH_VAR to the Calculated Key Figures screen and enter a description like this:
1 |
Sales Growth Rate |
- To display the current date using a formula variable called DATE_VAR that is replaced by a formula that uses a predefined function SYST_DATE() that returns the system date, drag and drop DATE_VAR from the Variables screen to
Title screen. In Properties pane, enter a prefix or suffix for variable if needed. For example, if you want to display current date using DATE_VAR that is replaced by
formula like this:
1 |
SYST_DATE() |
You can drag and drop DATE_VAR to Title screen and enter a prefix like “Sales Report as
of “.
- To display the current fiscal year using a formula variable called FISC_YEAR_VAR that is replaced by a formula that uses a predefined variable 0CURMEM_FISCVARNT that returns the current member of the fiscal year variant characteristic, drag and drop FISC_YEAR_VAR from the Variables screen to the Selections or Formulas screen. In the Properties pane, enter a selection or a formula for the structural component and include the variable name enclosed by & signs (for example, &VAR_NAME&). For example, if you want to display the current fiscal year using FISC_YEAR_VAR that is replaced by a formula like this:
1 |
&0CURMEM_FISCVARNT& |
You can drag and drop FISC_YEAR_VAR to the Selections screen and enter a selection like this:
1 |
Fiscal Year = &FISC_YEAR_VAR& |
Conclusion
In this blog post, we have shown you how to create and use formula variables in SAP BW/4HANA queries with examples. By using formula variables, you can perform calculations or transformations on the data and make your queries more flexible, dynamic and user-friendly.
We hope you found this blog post helpful and informative. If you have any questions or feedback, please feel free to leave a comment below.
Disclaimer: This content is generated by AI.