A proposal for #DAX Code Formatting #ssas #powerpivot #tabular
- by Marco Russo (SQLBI)
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!