cancel
Showing results for 
Search instead for 
Did you mean: 

How did I format my DAX expression in a post?

To format a DAX expression, I utilize the HTML view of the posts to copy in a formatted div tag and the html of the formatted DAX expression generated by https://www.daxformatter.com/.

 

  1. Click on the HTML button in the top bar of the post (you may need to click "..." to have it show)
  2. Paste in the <div></div> tag below.
  3. Copy DAX expression.
  4. Paste into https://www.daxformatter.com/ and then click "Copy HTML".
  5. Paste in the HTML DAX code from dax formatter before </div> (where the comment is).
  6. Click OK.

The formatted <div> tag (which can be further modified as you like!):

 

<div style="background: #F5F2F0; border: 1px solid lightgrey; border-radius: 10px; padding: 10px 10px 10px 10px; font-family: Courier, monospace; margin: 5px 5px 5px 5px; font-size: 12px;">
<!-- Insert DAXFormatter.com HTML code here -->
</div>

 

 

DataZoe_0-1606164559618.png

This will format the DAX expression to look like this:

Measure Cumulative =
CALCULATE (
    [Measure],
    FILTER (
        ALLSELECTED ( 'Date'[Date] ),
        ISONORAFTER ( 'Date'[Date], MAX ( 'Date'[Date] )DESC )
    )
)
Comments
Does not work. I get an error that says: "Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied." This is despite me following your recipe to the letter 😞
 
[7D Rolling Avg] =
VAR __daysCountRequired = 7
VAR __lastVisibleDay =
    MAX ( 'Event Dates'[Date] ) // The assumption here is that if there is
// an entry in the FactTable for a particular
// day, it means the measure you're trying to
// average is not blank for this day.
VAR __periodToAverageOver =
    TOPN (
        __daysCountRequired,
        SUMMARIZE (
            CALCULATETABLE ( FactTable, 'Event Dates'[Date] <= __lastVisibleDay ),
            'Event Dates'[Date]
        ),
        'Event Dates'[Date], DESC
    )
VAR __shouldCalculate =
    COUNTROWS ( __periodToAverageOver ) = __daysCountRequired
VAR __average =
    IF ( __shouldCalculateAVERAGEX ( __periodToAverageOver, [Your Measure] ) )
RETURN
    __average

@daxer-almighty You are right! I forgot to mention you need to CLOSE the div tag after pasting in the HTML DAX with the </div>

 

I will paste in the whole <div .... > </div> then paste the formatted DAX between the tags:

 

 

 

<div style="background: #F5F2F0; border: 1px solid lightgrey; border-radius: 10px; padding: 10px 10px 10px 10px; font-family: Courier, monospace; margin: 5px 5px 5px 5px; font-size: 12px;">
<!-- insert DAX formatter HTML here -->
</div>

 

 

 

[7D Rolling Avg] =
VAR __daysCountRequired = 7
VAR __lastVisibleDay =
    MAX ( 'Event Dates'[Date] ) // The assumption here is that if there is
// an entry in the FactTable for a particular
// day, it means the measure you're trying to
// average is not blank for this day.
VAR __periodToAverageOver =
    TOPN (
        __daysCountRequired,
        SUMMARIZE (
            CALCULATETABLE ( FactTable, 'Event Dates'[Date] <= __lastVisibleDay ),
            'Event Dates'[Date]
        ),
        'Event Dates'[Date], DESC
    )
VAR __shouldCalculate =
    COUNTROWS ( __periodToAverageOver ) = __daysCountRequired
VAR __average =
    IF ( __shouldCalculateAVERAGEX ( __periodToAverageOver, [Your Measure] ) )
RETURN
    __average

 

Thank you for bringing this to my attention and I'll work to get the post updated!

@daxer-almighty I have revised the article, are you able to get it to work now? thank you!