Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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 syntax of CALCULATE function, DATESMTD seems like a Filter.

But, here it is not filtering anything. It is just changing the context of calculation to be done per month-to-date.

Then, why is DATESMTD function in the example above considered and placed as "FILTER" in CALCULATE formula?

Is FILTER not equivalent to removing items?

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@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


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

AlB
Super User
Super User

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

 

SU18_powerbi_badge

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.

 

View solution in original post

4 REPLIES 4
AlB
Super User
Super User

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

 

SU18_powerbi_badge

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.

 

Fowmy
Super User
Super User

@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


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Thanks @Fowmy that explanation helped. Just a small follow-up query:

Does my explanation below make any sense? I mean does it support, counter your explanation or is it incorrect totally?

DATESMTD (DateTable[Date]) which according to CALCULATE function's syntax appears as being a filter is actually just a context. And when we hover over that FILTER part in the formula- PBI's intelligence suggests that [Filter1] "evaluates an expression in a context modified by filters". Which seem to suggest that even though if it doesn't remove (filter) items it still does calculate the expression per the context provided by DATESMTD

@Anonymous 

You are right. One point on removing filters in addition to adding filters is that CALCULATE also accepts filter modifiers.


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.