Forum Discussion

Newcolator's avatar
Newcolator
Icon for Helper II rankHelper II
2 years ago
Solved

Commenting out first line in DAX

Hi

 

Is it not possible to add comments at the top of a DAX formula?

 

I type this:

 

// same as rejected closed, but returns nulls for missing data so line charts don't show legends for 0 lines
Rejected Closed 2 =
VAR RC = sum('FACT CLAIM'[closed_rejected_count])
RETURN RC
 
When I press enter it adds the second line to the first and calls the measure "// same as rejected...."
 
// same as rejected closed, but returns nulls for missing data so line charts don't show legends for 0 linesRejected Closed 2 =
VAR RC = sum('FACT CLAIM'[closed_rejected_count])
RETURN RC
 
I'm using Nov 2023 version.
  • In DAX , the standard way to add comments is either using two forward slashes `//` for single-line comments or the `/* */` syntax for multi-line comments. These comments are generally used to explain the code, making it easier to understand its purpose and functionality.

    However, it's important to note that DAX comments are typically not allowed in the names of measures or columns themselves. When you attempt to create a measure and start the definition with a comment, the Power BI or Analysis Services environment might interpret your comment as part of the measure's name if the comment is placed directly above the measure definition without a blank line or is not properly recognized by the editor you're using.

     

    Rejected Closed 2 =
    // put your comment here
    VAR RC = SUM('FACT CLAIM'[closed_rejected_count])
    RETURN RC
    

5 Replies

  • In DAX , the standard way to add comments is either using two forward slashes `//` for single-line comments or the `/* */` syntax for multi-line comments. These comments are generally used to explain the code, making it easier to understand its purpose and functionality.

    However, it's important to note that DAX comments are typically not allowed in the names of measures or columns themselves. When you attempt to create a measure and start the definition with a comment, the Power BI or Analysis Services environment might interpret your comment as part of the measure's name if the comment is placed directly above the measure definition without a blank line or is not properly recognized by the editor you're using.

     

    Rejected Closed 2 =
    // put your comment here
    VAR RC = SUM('FACT CLAIM'[closed_rejected_count])
    RETURN RC
    
  • Hello Newcolator,

     

    Can you please try the following workaround:

     

    1. Start the Formula Normally

    Rejected Closed 2 =
    VAR RC = SUM('FACT CLAIM'[closed_rejected_count])
    RETURN RC
    

    2. Edit the Formula to Add Comments

    // same as rejected closed, but returns nulls for missing data so line charts don't show legends for 0 lines
    Rejected Closed 2 =
    VAR RC = SUM('FACT CLAIM'[closed_rejected_count])
    RETURN RC
    

    3. Use Multi-line Comments as an Alternative

    /*
    same as rejected closed, but returns nulls for missing data so line charts don't show legends for 0 lines
    */
    Rejected Closed 2 =
    VAR RC = SUM('FACT CLAIM'[closed_rejected_count])
    RETURN RC
    

    Hope this helps!

  • _AAndrade's avatar
    _AAndrade
    Icon for Resident Rockstar rankResident Rockstar

    Hi,

    If you want to put a description on a measure you can use the description box on the properties ribbon of model view.

     

    Output:

     

    Or put your description after define the name of your measure, like this:

     



     

  • DOLEARY85's avatar
    DOLEARY85
    Icon for Resident Rockstar rankResident Rockstar

    Hi, 

     

    Comments before measure names is not supported, you can add it after the measure name, on a new line before the statement:

     

    linesRejected Closed 2 =
    //same as rejected closed, but returns nulls for missing data so line charts don't show legends for 0
    VAR RC = sum('Table'[Column1])
    RETURN RC
     
    If I answered your question, please mark my post as solution, Appreciate your Kudos 👍