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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

the difference between filter() and datesbetween()

Hi, 

 

I'm trying to understand the difference between the two measures below. I thought they will generate the same results, except option1 filters calendar[Date] through filter() function while option 2 filter calendar[Date]  via datesbetween(). 

 

However, these two measures generate different results. It looks filter() always take current filter context (year-month) as a default context and apply conditions on top of it. Datesbetween () take the whole calendar[Date] as the starting point, ignoring date context in the matrix table context. 

 

Is that normal that datesbetween behaves this way? I have never heard of a function (except "all()", "allexcept()") that would ignore current filtering context automatically. 

 

 

option1

Rolling 12 Months #Exits =
VAR Maxdate =
MAX ( 'Calendar'[Date] )
VAR Mindate = Maxdate -364
RETURN
CALCULATE (
COUNTROWS ( Headcount ),
USERELATIONSHIP ( 'Calendar'[Date], Headcount[Exit Date] ),
NOT ISBLANK ( Headcount[Exit Date] ),
FILTER (
'Calendar',
AND (
'Calendar'[Date] <= Maxdate,
Calendar[Date] > Mindate
)
)
)
 opt 2
#leavers 2 =
VAR maxdate = MAX ( 'Calendar'[Date] )
VAR mindate = maxdate - 364
VAR rolling_12_month_leavers =
CALCULATE (
COUNTROWS ( Headcount ),
NOT ISBLANK ( Headcount[Exit Date] ),
USERELATIONSHIP ( 'Calendar'[Date], Headcount[Exit Date] ),
DATESBETWEEN (
'Calendar'[Date],
mindate,
maxdate
)
)
RETURN
rolling_12_month_leavers
two types of filter.PNG
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , time intelligence function is used outside filter function has a different impact than the one you have used in filter

refer if this can help

http://dataap.org/blog/2019/04/22/difference-between-calculate-with-and-without-filter-expression/

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , time intelligence function is used outside filter function has a different impact than the one you have used in filter

refer if this can help

http://dataap.org/blog/2019/04/22/difference-between-calculate-with-and-without-filter-expression/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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