Ja vēl neesat iepazinušies ar Standard-BI vispārējo pārskatu un datu analīzes un jaunu atskaišu izveidošanas funkcionalitātes aprakstiem, lūdzu iepazīstieties ar tiem. Šī instrukcija apraksta kā definēt jaunus aprēkināmos rādītājus izmantojot MDX kalkulāciju formulas.
Katra kuba dimensija sastāv no vienas vai vairākām hierarhijām ar vienu vai vairākiem hierarhijas līmeņiem. Katru hierarhijas līmeni savukārt veido dimensiju rādītāji. Eksistē normālie rādītāji, kuri ir importēti no datubāzes failiem vai aplikācijām, taču papildus tiem ir iespējams definēt arī Aprēķināmos rāditājus ( calculated members ) izmantojot kalkulāciju formulas . Kalkulāciju formulas tiek definētas izmantojot MDX vaicājumu valodu.
Eksistē speciāliāla dimensija Rādītāji ( Measures ), kura satur visus ieimportētos rādītājus. Apreķināmie rāditāji visbiežak tiek definēti tieši Rādītāju dimensijā, un tie tiek saukti par Aprēķināmajiem rādītājiem.
Define new calculated member
Ja vēlaties definēt jaunu aprēķināmo rāditāju tad paplašiniet attiecīgo dimensiju ( piem. Measures ) un palašiniet arī Aprēķināmo rādītāju sadaļu. |
|
|
|
|
|
| |
If you would like to define new calculated member then click on Define new link, if you would like to edit (or delete) existing calculated member then click on edit link. If you do not have rights to edit calculated members in current account then you will see just show link to see definition of existing calculated members. When you define new or edit existing calculated member you will see the following calculated member definition form: |
|
|
|
|
|
| |
Each calculated member should have name (unique within dimension) and calculation formula (the rest of tutorial will teach how to write calculation formulas). In addition you can specify how calculated member value should be formatted (e.g. as integer, decimal, date or using default formatting). From the right sidebar you can quickly select other members, dimensions, operators or functions to insert them in calculation formula. After defining calculated member formula press Update to save it or Delete to delete existing calculated members or Cancel to discard any changes. If calculated member formula will be invalid then corresponding error message will be displayed. Do not modify or delete pre-defined calculated members that were created by source application import - their original definition will be recreated next time you will perform source application import. If you need to create modified version of existing pre-defined calculated member then copy its calculation formula and create new calculated member with different name and modify copied calculation formula for the new calculated member. Let's start writing some calculation formulas! Following examples will use Sales demo cube dimensions and measures to illustrate creation of calculation formulas. |
|
|
|
Dimension, hierarchy, level and member names
When writing calculation formulas you will need to reference dimensions, dimension hierarchies, hierarchy levels and other existing dimension members. In MDX query language all names are enclosed in square brackets [ ]. To reference dimension you just enclose its name in square brackets, e.g. Customers, Time or Measures. If dimension has just one hierarchy then you can reference the primary hierarchy in the same way as dimension, e.g. Customers or Measures. When you import Time dimension then it automatically will create main hierarchy (with year, quarter, month and day levels) as well as Weekly hierarchy (with year, week and day levels). Time will reference Time dimension main hierarchy but Time.Weekly will reference Time dimension Weekly hierarchy. When you expand specific dimension and expand All hierarchy level members then you see names of all main hierarchy levels. You can reference particular hierarchy level with dimension or hierarchy name.level name. E.g. Customers.City references City level of main hierarchy of Customers dimension. In case of Time dimension use Time.Year, Time.Quarter, Time.Month, Time.Day to reference main hierarchy levels and Time.Weekly.Year, Time.Weekly.Week, Time.Weekly.Day to reference weekly hierarchy levels. Each dimension typically will have default All member which can be used to get totals of measures per this dimension. If Customers dimension has default All member named All Customers then you can reference it with Customers.All Customers. As default All member can be renamed it is safer to use Customers.DefaultMember to get the same result. In case of Time dimension there are two default All members for each hierarchy - Time.DefaultMember and Time.Weekly.DefaultMember. When you want to reference top level dimension members then you use dimension or hierarchy name.member name. E.g. Customers.USA will reference USA member from top level Country level. To reference detailed level dimension members* you need to specify full "hierarchy path" to this member, e.g. Customers.USA.CA to reference CA member in State Province level under USA parent member. Or Customers.USA.CA.San Francisco to reference city etc. All measures are in top level of Measures dimension and you can reference them with e.g. Measures.Store Sales, Measures.Store Cost etc. |
|
Simple arithmetic calculations
Now that you know how to reference other existing measures and other dimension members we can create simple arithmetic calculations. If we have Measures.Store Sales and Measures.Store Cost measures then we can define new calculated measure Profit (which will have full name Measures.Profit) with formula:Measures.Store Sales - Measures.Store Cost When you will use this new measure Profit in your Standard-BI reports then for any combination with other dimension values this formula will calculate difference between Store Sales measure value and Store Cost measure value. You can use defined calculated measures also in other calculated measures that you define later (it is important to define them in right sequence - you cannot use calculated member that you will define later than current calculated member). For example, you can now define Measures.Margin % with formulaMeasures.Profit / Measures.Store Sales and it will calculate margin as number from 0 to 1. If you would like to display results as percentage value then change Formatting of this calculated measure to use integer or decimal percentage formatting. You can perform arithmetic calculations also for calculated members in other dimension. For example, you could define Customers.West coast calculated member in Customers dimension with formulaCustomers.USA.CA + Customers.USA.OR + Customers.USA.WA and now when you will combine in reports Customers.West coast with Measures.Store Sales you will get total sales for all these three states together. If you will combine it with Measures.Profit you will get total profit for all these three states. |
|
Moving across dimension levels
When you use Measures.Store Sales then it will calculate Store Sales measure value for other corresponding dimension members for each row / column in report. If in your calculation formula you would like to override some other dimension value then you need to use tuples which is combination of members from different dimensions. MDX syntax for tuples is (member_1, member_2, ..., member_n). For example, if you would like to get Store Sales measure value for all customers then you would use tuple (Measures.Store Sales, Customers.DefaultMember. |
|
Moving in time
As you can move to different dimension hierarchy levels you can also move to different dimension members in the same dimension. It is typically used in Time dimension when you want to compare measures between different time periods or aggregate time period range.
|
|
Sets
Now you know you to navigate to individual dimension members. But quite often you would like to perform operations on set of dimension members, for example, find sum or average value of some measure over selected set of dimension members.
|
|
Sets of time periods
There are additional useful set selection methods for Time periods
|
|
Set operations
There are several operations that you can perform on sets:
|
|
Aggregates
Now that you know how to select different sets of dimension members you can calculate different aggregated values from these sets:
|
|
Conditions
You can write formulas with conditions and different results based on condition evaluation using IIF and CASE functions. For simple IF / THEN / ELSE type of conditions use IIF(condition, if_true_expression, if_false_expression) (notice that there are two I letters in IIF), for exampleIIF(Measures.Profit > 0, 'Profit', 'Loss')
|
|
Member properties
Dimension members has some default properties (like .Name) as well as they can have additional custom properties. Standard-BI source application import (e.g. from Basecamp, Highrise or JIRA) are also importing additional dimension fields from source systems. MDX has standard Properties function to access member properties but Standard-BI defines improved getProperty function (which will return empty result instead of exception if no property is defined for current dimension level). For example, Highrise import adds Created date property for all imported deals. The following expression returns Created date property value for Deals dimension current memberDeals.CurrentMember.getProperty('Created date') |
|
Date type conversion
Sometimes you might need to convert string expression to integer, decimal or date expression (for example, to convert Highrise custom field string value to corresponding type to be able to use it in further calculations). There are several functions available for data type conversions:
|
|
Time difference calculations
Standard-BI defines additional function DateDiffDays(from_date, to_date) which will return difference in days between two dates. It can be used together with Now() function (which returns current time) to get distance in days between selected time dimension member and current date, for exampleDateDiffDays(DateParse(Time.CurrentMember.Name), Now()) In addition Standard-BI defines function DateAddDays(date, number_of_days) which will return new date in the past (if numberofdays is negative) or in future (if numberofdays is positive). For example, this will return date which is 5 days from current Time dimension member date.DateAddDays(DateParse(Time.CurrentMember.Name), 5) Sometimes it is useful to get Time dimension member which corresponds to actual current date. This can be done with Standard-BI specific dimension hierarchy level property CurrentDateMember. For example, these expressions will return month of current date and week of current dateTime.Month.CurrentDateMember Time.Weekly.Week.CurrentDateMember If there is no Time dimension level that corresponds to current date (e.g. if data for current month or week are not yet imported) then CurrentDateMember will return the last period before current date which is present in Time dimension corresponding level. |
|
Default values
Sometimes you might want some default value if some measure or function will return empty value. In these cases you can use CoalesceEmpty(expression, default_value) function, for exampleCoalesceEmpty(Measures.Store Sales, 0) |
|
Comments
It is possible to write comments in calculation formulas. Use comments either to describe some non-obvious complex calculations or also commenting is valuable during writing and testing calculation formulas - when something is not working as expected then comment all formula lines and leave uncommented just some part of formula that you would like to debug.-- one line comment expression – comment until end of line /* multi line comment */ |
|
List of all MDX functions
This tutorial covered most frequently used MDX functions and examples how to use them. If you didn't find what you need then take a look at list of all MDX functions. If you have any unclear questions or issues when writing calculation formulas then contact Standard-BI support. |
|