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.
Kā definēt jaunu Aprēķināmo rādītāju ?
Ja vēlaties definēt jaunu aprēķināmo rādītāju, tad paplašiniet attiecīgo dimensiju ( piem. Measures ) un paplašiniet arī Aprēķināmo rādītāju sadaļu. |
|
|
|
|
|
| |
Ja vēlaties izveidot jaunu aprēķināmo rādītāju, tad klikšķiniet uz Veidot jaunu ( Define New ), ja vēlaties labot vai izdzēst eksistējošu aprēķināmo rādītāju uzklikšķiniet uz Edit . Ja jūsu lietotāja kontam nav piešķirtas tiesības rediģēt aprēķināmos rādītājus, tad jūs redzēsiet tikai iespēju Parādīt ( Show ) un varēsiet apskatīt tikai jau eksistējošu Aprēķināmo rādītāju definīcijas un formulas. Kad Jūs definēsiet jaunu vai labosiet eksistējošu aprēķināmo rādītāju, jūs redzēsiet sekojošu logu : |
|
|
|
|
|
| |
Katram aprēķināmajam rādītājam ir nosaukums ( unikāls dimensijas ietvaros) un aprēķinu formula ( pārējā apmācības daļa mācīs, kā rakstīt aprēķinu formulas ). Turklāt jūs varat norādīt, kā aprēķinātā rādītāja vērtība ir jāformatē ( piemēram, kā skaitlim , decimāldaļai, datumam vai izmantojot noklusējuma formatējamu ) . Labajā sānu joslā, jūs varat ātri izvēlēties citus rādītājus, dimensijas, operācijas vai funkcijas, lai ievietotu tos aprēķina formulā . Pēc tam, kad esat definējis aprēķināmā rādītāja formulu, spiediet Atjaunot ( Update) lai saglabātu to, vai Izdzēst ( Delete), lai izdzēstu konkrēto aprēķināto rādītāju, Atcelt (Cancel), lai atceltu izmaiņas. Ja aprēķināmā rādītāja formula būs sastādīta nepareizi, ekrānā parādīsies kļūdas paziņojums. Ķersimies klāt pie formulu rakstīšanas! Sekojošie formulu piemēri tiks veidoti uz Pārdošana kuba (Sales cube) dimensijām un rādītājiem. |
|
|
|
Dimension, hierarchy, level and member names
Kad rakstīsiet formulas jums būs jāizmanto dimensijas, dimensiju hierarhijas, hierarhiju līmeņi un citi eksistējošu dimensiju rādītāji. MDX vaicājumu valodā visi nosaukumi tiek likti kvadrātiekavās [ ]. Lai atsauktos un izmantotu dimensiju, vienkārši ievietojat formulā tās nosaukumu kvadrātiekavās, piem. Klienti [Customers],Laiks [Time] vai Rādītāji [ Measures ] . Ja dimensijai ir tikai viena hierarhija, ta jūs varat ievietot galveno hierarhiju tieši tāpat kā dimensiju, piem. Klienti [Customers], vai Rādītāji [ Measures ]. Kad jūs importējat Laika ( Time ) dimensiju , tad automātiski tiks izveidota arī Galvenā hierarhija ( ar gadu, ceturkšniem, mēnešiem un dienu līmeņiem), kā arī Nedēļas hierarhija ( ar gadu, nedēļu un dienu līmeņiem). Līdz ar to Laiks (Time ) definēs laika dimensiju, bet Laiks.Nedēļas ( Time.Weekly) definēs laika diemnsiju Nedēļas ( Weekly ) hierarhiju. 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. |
|