Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Theory Question on using DATESMTD with CALCULATE

Hi All, MS documentation provides this example below to explain DATESMTD function: CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), DATESMTD(DateTime[DateKey]))   My question is that per the sy...
  • Fowmy's avatar
    5 years ago

    Anonymous 

     

    CALCULATE function accepts the following type of parameters after the Expression.

    • Boolean filter expressions
    • Table filter expressions
    • Filter modification functions

    In your MTD example it is a Table Filter expression that is applied here. CALCULATE filters the DateTime[DateKey] column with a range of dates from 1st of the month to the current date in the background when you apply DATESMTD function.

    Hope this clear your question?

    Articles: 
    https://dax.guide/calculate/
    https://docs.microsoft.com/en-us/dax/calculate-function-dax


  • AlB's avatar
    5 years ago

    Hi Anonymous 

    It's a valid point. It all comes down to terminology. Here you should read FILTER not as the usual selection of rows operation but as filter context.  The whole point of  CALCULATE is evaluating the expression in a modified filter context.  Each of those "FILTER" arguments described in the documentation is used for modifying the filter context   and can be either a:

    A) filter removal operation (such as ALL, ALLEXCEPT, ALLNOBLANKROW)

    B) filter restore operation (ALLSELECTED)

    C) table expression, returning a list of values for one or more columns or for an entire expanded table

     

    Point C) would be the one at play in your DATESMTD example 

    Have a look at https://dax.guide/calculate/  for a more comprehensive overview

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.