Convert MDX into DAX Part3

Few more functions to add flexibility to your DAX queries like MDX.


  • We usually come across reporting requirement where a fix format of data. We start looking for different possible FORMAT which can make our task easy.

    FORMAT(<Value to be formatted>,<Format Pattern>)

    It’s easily understandable what this function will do but need to figure what possibilities it can give us.Example:

    ('Internet Sales'
    ,"Sales Amount",FORMAT('Internet Sales'[Internet Total Sales],"Currency")
    Result is:

    Here Currency format gives $ sign, Thousand separator and 2 decimal specification.

    So there is a list of these formats and this link will be best place to get other possible format. But question arise for user defined patterns.

    So below is some part of introduction to most common characters used with FORMAT function to get different results:

    0 Displays 0 or number in the position assigned
    # Displays nothing or number in position assigned
    . Represent decimal place. We use different combination of 0s and #s to left and 0s to right to get formatted values in decimal places
    % First multiplies the number with 100 and display symbol % to the right of the number
    , Used to show thousand separators with the combination of 0s and #s. We can define multiple scaling using different places of separators.
    : Time separator
    $ Used at extreme left of numbers to represent currency. Similarly + and – symbol can be sued.
    \ Displays next character whatever it is. For the character we can use in normal formatting like “, \, /, ., , etc.

    Examples can be
    FORMAT(“123.569”, “$#,##0”); FORMAT(“123.569”, “#,##0”); FORMAT(“123.569”, “#0.00%”) etc.


  • This function does two things:
    a)      Order the result set obtained from Tabular Expressions (Descending or Ascending  order)
    b)      Give rows from the Top of resultOne drawback here, most of the times it doesn’t show the final top result in order of descending. We need to explicitly do ORDER BY.

    TOPN(<number of rows required>, <table or tabular expression>, <orderBy expression>, <Order (0 or 1)>)

    Order argument is option with value
    0: Default, descending order of Order By Expression
    1: ascending order of Oder By Expression
    Required top 10 State on the basis of Internet Sales Amount in MDX.

    SELECT {[Measures].[Internet Total Sales]} ON 0
    {[Geography].[State Province Name].[State Province Name].MEMBERS},
    [Measures].[Internet Total Sales], DESC)  ON 1
    FROM [AdventureWorks_Test]

    Same result set in DAX:

    'Internet Sales'
    ,'Geography'[State Province Name]
    ,"Sales Amount",'Internet Sales'[Internet Total Sales]
    ,'Internet Sales'[Internet Total Sales]
    ORDER BY 'Internet Sales'[Internet Total Sales] DESC

    Last ORDER BY in DAX query to arrange top 10 States obtained by query in Descending order of Sales Amount.


Posted on August 25, 2012, in DAX, SSRS Reporting and tagged , , , , , , , . Bookmark the permalink. 1 Comment.

  1. The way of explaining the function “Evaluate” in DAX is very good, can I get the explanation of the remaining functions as well ? , Thanks.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: