Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

What is a calculated member and when to use calculated members

This tutorial explains how to define new calculated members and measures using MDX expressions (or formulas). If those words do not make sense to you, we advise getting to know the main flex.bi concepts and learn how to create reports and then come back to this section again.

What is MDX?

MultiDimensional eXpressions (MDX) is a query language for querying and manipulating the multidimensional data stored in OLAP (online analytical processing) data cubes. MDX syntax is similar SQL syntax or to spreadsheet formulas. Below is an example of a very simple MDX query:

...

MDX implementations vary, and many MDX documentation resources are specific to certain niche products or standards.

MDX Used in flex.bi

Calculated members and calculated measures can be used to add business logic to a report and a data cube. Most common use cases for calculated members and measures are to group particular items of interest, dynamically change time according to the current date or selected period and, most importantly, derive new measurements from existing data. Calculated members and measures are defined using the MDX (multidimensional expressions) query language which is the main query language implemented by Mondrian (https://mondrian.pentaho.com/documentation/mdx.php)

What you should know

Mastering how to write MDX expressions is initially quite difficult. Don't worry, you will get along quite well if you will follow some ground rules. MDX is a language and to use it for calculations it is enough to understand some base words (data types and functions) and how to use a dictionary (list of available functions).

...

[Time].[2019].[Q2 2019].[May 2019]

In MDX query language, all names of measures, dimensions, dimension hierarchies, hierarchy levels, and dimension members are enclosed in square brackets []. To reference a dimension, you just enclose its name in square brackets, e.g., [Customers], [Measures], [Time]To reference a particular member, enclose each name of the path in square brackets, e.g., [Customers].[USA].[CA], [Time.Weekly].[2019].[W31, Jul 29 2019] or [Measures].[Store Sales].

  • If a dimension has just one hierarchy, it automatically is also the primary hierarchy. And you can refer to the primary hierarchy in the same way as a dimension by mentioning just a dimension name, e.g. [Customers] or [Measures].
  • If a dimension has two or more hierarchies (like Time dimension), then you should refer dimension name and hierarchy name. For example, a reference to  Time dimension Weekly hierarchy is [Time.Weekly]. In Time dimension primary hierarchy (year, quarter, month day) does not have a specific name, and you can refer to it by mentioning just a dimension name [Time].

Each dimension typically will have a default All member which can be used to get totals of measures by this dimension. If Customers dimension has a default All member named All Customers, then you can reference it with by its name [Customers].[All Customers] or [Customers].CurrentHierarchy.DefaultMember to get the same result. In Measures, all measures are at the top level, and you can reference them with as [Measures].[Store Sales], [Measures].[Store Cost] etc.

How to define a new calculated member

...

Dimension members have some default properties like .Name and .Key as well as they can have additional custom properties. flex.bi source application import (e.g. from HansaWorld, Tilde or Jira) is also importing additional dimension fields from source systems. Note that a property holds information about a particular member and could be anything that describes that member details. 

For example, a User dimension member can be a person (user) and the property of each user can be an address (string), age (number), date of birth (date). In reports, properties are displayed only at a particular user level.

To access and retrieve property values, we recommend using MDX function get(). This function will return property value if a member has such property or an empty result if no property is defined for the current dimension level.

For example, Jira import adds the Invoice date the property for all imported Invoices. The following expression returns the Invoice date property value for the Invoice dimension current member:

...

-- annotations.drill_through_non_empty=false 
During drill through issue the calculation will be executed over all issues imported in the account ignoring any report context. It could slow down the drill through issues output significantly!

-- annotations.copy_as_user_defined=true
Enable the option to edit template measures in the recipient account. Changes made in those measures won't be overwritten during data imports.

Formatting 

When creating a new calculated measure you can choose the format for the output of results. 

...

FormattingComment
Numeric
  • #,###.## Decimal - Represents value as a decimal number.
  • #,### Integer - Represents value as an integer number.
Percentage
  • ##.##% Decimal percentage - Multiplies the cell value by 100 and displays the result as a decimal number with a percent (%) symbol. For example, 0.873 would be represented as 87.3%
  • ##% Integer percentage - Multiplies the cell value by 100 and displays the result as an integer number with a percent (%) symbol. For example, 0.873 would be represented as 87%
Date / Time
  • mmm dd yyyy Month Day Year - Represents the date in format 'Month Day Year' e.g. 'Jul 28 2020'
  • mmm yyyy Month Year - Represents the date in format 'Month Year' e.g. 'Jul 2020'
  • yyyy-mm-dd ISO format date The purpose of ISO 8601 standard is to provide an unambiguous and well-defined method of representing dates and times to avoid misinterpretation of numeric representations of dates and times. e.g. '2020-07-28'
  • yyyy-mm-dd hh:mi:ss Date and time - Represents the date in format 'Date and time' e.g. '2020-07-28 16:51:20'
Duration
  • ##d ##h ##m Days, hours, minutes - Represents duration in days, hours, and minutes. For formatting to work correctly the result has to be in minutes.
  • ##h ##m Minutes - Represents duration in hours and minutes. For formatting to work correctly the result has to be in minutes.
  • ##h ##m ##s Seconds - Represents duration in hours, minutes, and seconds. For formatting to work correctly the result has to be in seconds. Format adjusted dynamically depending on the results (#s if integer below 1 minute, #.###s if below 1 min, #m #s if below 1hour). 

Size
  •  Bytes - Represents the size of data units. For formatting to work correctly the result has to be in bytes. It will adjust dynamically depending on the results (##.##MB, ##.##KB, etc.).

Text

  • Plain - Represents value as a text without formatting (string).
  • Markdown - Use lightweight markup formatting language Markdown to show the rich text (bold, italic) or clickable URL links.
  • HTML - Use Hypertext Markup Language (HTML) for more advanced formatting, e.g., show an icon or image as a measure. Here is an example:

    Code Block
    CASE WHEN [Measures].[Issues created] > 0
    THEN
      "<span class='fal fa-unicorn'></span>"
    END

    The use of the HTML is limited to the following:

    • Allowed tags:a, abbr, b, br, code, dd, div, dl, dt, em,h1, h2, h3, h4, h5, h6, hr, i, img, li, nav, ol, p,pre, s, small, span, strong, sub, sup, table, tbody, td,tfoot, th, thead, tr, u, ul
    • Allowed attributes: alt, class, colspan, href, id, lang, rel, reversed,rowspan, scope, span, src, start, style, target
    • Allowed CSS properties: color, background-color, font-size, font-style, font-weight, text-transform,text-decoration, text-shadow, text-align, word-break, text-orientation

flex.bi uses Font Awesome icons and it is possible to refer to them in a calculated measure when using markdown formatting, e.g. 

See some examples here: https://flex.bi/bi/accounts/47/dashboards/1731-conditional-messages

NEW Sparkline

  • Sparkline - line - Represents the Sparkline JSON data as a line in a table or Gauge chart. The y-axis is adjusted to the measure values.
  • Sparkline - area - Represents the Sparkline JSON data as an area in a table or Gauge chart. The y-axis is adjusted to 0.
  • Sparkline - bar - Best used for representing one value to visually compare with values in other rows.

  • Sparkline - column - Represents the Sparkline JSON data as columns in a table or Gauge chart. The negative values are automatically highlighted in red. 

Custom

With this, you can change the result representation to another, e.g., mmmm yyyy will return you the full name of month and year ('July 2020').

For more details (and string templates) see how to Format string content.

Shortcuts

You can use the following keyboard shortcuts in the formula editor:

...