Macro in BEx
Macro in BEx
the user which can be easily dealt with by writing small macro codes in our workbook. In this document, I have mentioned the specific steps for creating and embedding a macro code in the workbook, I have illustrated this with the help of few scenarios.
Scenario:
The requirement is to develop a report which shows the forecast accuracy of various products. The accuracy is calculated at different levels like plant level, national level, zone level etc. Why we needed macro: The BEX query has 31 selections in the key figure structure, each representing a date in a month. In analyzer, the output of this query will mapped to another locally created table which has to show rolling sum. This table will then be used to draw a graph representing daily sales.
Day2 50 300
Day2 90 300
Table 2 is being filled up by table 1, which actually is BEX query. The excel formula to add up the previous cell has been applied to all the cells. This causes an issue; all the cells up to Day31 get filled up in table 2. Because of this, the graph which has been mapped to table 2 to show daily accumulated sales shows values till day 31. We want the graph to show the data till current day -1. This can be easily achieved using the macros. With a macro code well check the current date and then delete the values from all the cells which fall after the required day.
Here we see that the lines appear till day 15, actually they should have appeared till current date only.
To view the VBA editor just go to the sheets and right click on them:
A list of the options appears as shown in the above screenshot. Select the View code option to start the editor. The initial editor looks like the following:
All the sheets present in the workbook are listed here. They are named as sheet1, sheet2 etc. In program that write, we always refer to them as sheet1, sheet2 etc and not by the description that we provide to the sheets. This shows the various properties of the sheet.
In the present case, we want the code to be executed when the sheet is activated. So we select the Activate function.
The code has been written to populate the table for the graph up to the current day only:
The table from which the graph draws its data appears as follows:
The line in the graph appears till the current date only:
This is a very simple situation which I have come across; there might be several situations where a simple VBA code can resolve a complex issue. Most of the time, BW consultants tend to overlook the usefulness of the power of excel that is inherently added to the analyzer along with the BEX.
Here are few links that will help you get started with the macro:
1. http://www.few.vu.nl/~rbekker/VBA-intro.pdf 2. http://www.staff.city.ac.uk/~fring/ExcelVBA/