Académique Documents
Professionnel Documents
Culture Documents
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 1: 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. Divisions A B Day1 100 200 Day2 50 300 Day2 90 300 Day3 100 500 Day4 900 100 Day5 500 200 Day6 300 400
Divisions A B
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.
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.
APE = forecast-sales/sales Material plant Salestotal quantity Forecast price Total value APE Abs value(total value*APE) Forecast accuracy(1Abs value/total value) 0.5 0.75 0.8
1 2 3
900 500 80
10 10 10
10000
500
700
10
5000
0.4
2000
0.6
Material
Salestotal quantity
Forecast
APE
10000
1600
2180
10
BEX was calculating the Abs value by summing up the individual values which in this case would be 6200. So the accuracy was calculated as : 6200/16000 =