A proposal for #DAX Code Formatting #ssas #powerpivot #tabular

Posted by Marco Russo (SQLBI) on SQL Blog See other posts from SQL Blog or by Marco Russo (SQLBI)
Published on Mon, 22 Oct 2012 12:10:00 GMT Indexed on 2012/10/22 17:13 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

I recently published a set of rules for DAX code formatting. The following is an example of what I obtain:

CALCULATE (
    SUMX (
        Orders,
        Orders[Amount]
    ),
    FILTER (
        ALL ( Customers ),
        CALCULATE (
            COUNTROWS ( Sales ),
            ALL ( Calendar[Date] )
        ) > 42 + 8 – 25 * ( 3 - 1 )
            + 2 – 1 + 2 – 1
            + CALCULATE (
                  2 + 2 – 2
                  + 2 - 2
              )
            – CALCULATE ( 4 )
    )
)

The goal is to improve code readability and I look forward to implement a code formatting feature in DAX Studio. The DAX Editor already supports the rules described in the article.

I am also considering whether to add a rule specific for ADDCOLUMNS / SUMMARIZE because I would like to see the “pairs” of arguments to define a column in the same row or with a special indentation rule (DAX expression for a column is indented in the line following the column name).

EVALUATE
CALCULATETABLE (
       CALCULATETABLE (
        SUMMARIZE (
            Audience,
            'Date'[Year],
            Individuals[Gender],
            Individuals[AgeRange],
            "Num of Rows", FORMAT (COUNTROWS (Audience), "#,#"),
            "Weighted Mean Age",
                SUMX (Audience, Audience[Weight] * Audience[Age]) / SUM (Audience[Weight])

        ),
        SUMMARIZE (
            BridgeIndividualsTargets,
            Individuals[ID_Individual]
        ),
        Audience[Weight] > 0
       ),
       Targets[Target] = "Maschi",
    'Date'[Year] = 2010,
    'Date'[MonthName] = "January"
)

I would like to get feedback for that – you can use comments here or comments in original article. Thanks!

© SQL Blog or respective owner

Related posts about DAX

Related posts about PowePivot