In this session we’ll start building the Data Rules we need. First, we’ll take a look at the Data Rule editor and learn the difference between VIEW Rules and ACTION Rules. Then we’ll organize the calculations we outlined into different Data Rules. And lastly, we’ll configure the Calculate Trade Spend Rule.
In this session we’ll start building the Data Rules we need to calculate the values that populate our P&L Form.
First, we’ll take a look at the Data Rule editor and learn the difference between VIEW Rules and ACTION Rules. Then we’ll organize the calculations we outlined into different Data Rules. And lastly, we’ll configure the first Data Rule we need in Kepion.
A Data Rule is a component to define business rules through the Kepion UI. These rules generate SQL scripts in the application. The use of Data Rules is highly recommended as they’re both easier to use and maintain than raw SQL scripts.
There are two types of Data Rules: VIEW Rules and ACTION Rules. VIEW Rules generate SQL Views, which are virtual tables. VIEWs are dynamic and update automatically as the data changes.
ACTION Rules are updated on demand, and allow you to INSERT or DELETE the records in a partition. ACTION Rules are preferred when the resulting values need to be referenced in other rules.
Let’s return to the table we created in our Architecture Document and organize the calculations.
The accounts ‘Gross Sales Before Returns’ and ‘Cost of Goods Sold’ are both calculated from values in our Assumption Model— so let’s calculate both these values in the same Data Rule. As we’ll need to reference the Revenue numbers in other calculations, let’s make this one an ACTION Rule.
All of these values are calculated by multiplying revenue with rates in the Deflator Percent Model, so let’s perform all of them in the same rule, as well. For simplicity, let’s make this one a VIEW.
For the Post Invoice accounts we don’t actually need to calculate anything here, we just need to move the data from the Trade Spend Model to the Reporting Model. We can do this with a simple VIEW Rule as well.
And finally, the Gross Margin % is the ratio of Gross Margin to Gross Sales After Returns. As neither of these accounts are on the lowest level of the hierarchy, this calculation wouldn’t be a good candidate for Data Rules, as the values don’t exist as Fact Records. This calculation would be best represented with MDX, which we’ll get to later.
Here are the three Data Rules we’ll build in this application. Let’s get an overview of how these rules will interact with the Reporting Model. Calculate Revenue and COGS is an ACTION Rule, that will insert records into the Calculated Partition.
Then Calculate On-Sale Discounts will create a VIEW, using Deflator % values and some of the records created in the previous Rule. And finally, Calculate Trade Spend will create a VIEW to display the Post Invoice accounts.
As this is the simplest Rule, let’s begin there.
To create a new Data Rule, navigate to the All Data Rules tab and then click Add. Name it Calculate Trade Spend, and select VIEW.
In the Data Rule editor, we have a setup similar to the Dashboard editor, with a ribbon at the top containing different components to add, a panel on the side that’ll be an overview of the steps in our Rule, and the editor window in the middle where we’ll configure each component.
There are three steps to building a Data Rule. First, we need to choose where the data we’re using is coming from. Often this will be a partition, but we can also bring in data from the Dimension Tables, or another Data Rule.
The next step is making any transforms or calculations that we need, such as Joining two tables together, or multiplying values.
And then the last step is choosing where to publish the results to. In a VIEW Rule, the data will always be published to the Rule partition of the Model we choose.
For this rule, all we need to do is take the data from the Trade Spend Model and move it to the Reporting Model-- so for our Data Source we’ll select Trade Spend – Writeback. If you switch to the Preview tab, we can see a live version of the data we’re working with at each step.
As the Reporting Model has the exact same Dimensionality as the Trade Spend Model, we don’t need to transform the data in any way. We can just select Publish, and then choose the Reporting Model. Now we need to deploy the Application.
In the Rule Partition, we can see all the data we published. Also note the Rule column here, which shows us which Data Rule these entries are associated with. If we open our P&L Form, we can see the Post Invoice accounts have been filled in. The Post Invoice aggregation has also been calculated automatically.
In this session, we looked at the Data Rule editor and the difference between VIEW Rules and ACTION Rules. Then we organized the calculations into the Data Rules we need for the application. And lastly, we’ll configured our Publish Trade Spend Rule.
In our next session, we’ll look at designing an ACTION Rule to handle the calculations we need for our Revenue and COGS.