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
sathishsam
Helper I
Helper I

Is using Filter inside the Calculate makes any difference?

I have a DAX function written in 2 ways, i see that the 2nd one performs better always, then my question is where should i use the first once

 

1) Calculate ( SUM(TableA[Col1], TableA[Col2] = "Some Filter", 
FILTER(TableB, TableB[Col1] = "Some Filter") )

 

2) Calculate ( SUM(TableA[Col1], TableA[Col2] = "Some Filter", TableB[Col1] = "Some Filter") 

 

I am still learning DAX and its fun. Thanks for the help in advance

 

3 REPLIES 3
v-xuxinyi-msft
Community Support
Community Support

Hi @sathishsam 

 

The first parameter of the FILTER function is the table, and the second parameter is the filter condition, for example:

 

My sample:

vxuxinyimsft_0-1706845657692.png

 

Measure:

Measure = CALCULATE(COUNT('Date'[Date]), FILTER('Date', [Date] >= DATE(2023, 2, 22) && [Date] <= TODAY()))

 

Result:

vxuxinyimsft_1-1706845905735.png

My formula filters out dates in the range of February 22, 2023 to today to calculate how many dates there are in total.

 

For more details about Funtions I used, you can read related document link: 

FILTER function (DAX) - DAX | Microsoft Learn

COUNT function (DAX) - DAX | Microsoft Learn

CALCULATE function (DAX) - DAX | Microsoft Learn

 

Best Regards,
Community Support Team _Yuliax

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

sathishsam
Helper I
Helper I

Thank you for the reply. How do i write an optimized DAX in this case, the first one usually takes 5 to 6 times more than the second one.

talespin
Solution Sage
Solution Sage

Hi @sathishsam,

 

Calculate ( SUM(TableA[Col1], TableA[Col2] = "Some Filter", TableB[Col1] = "Some Filter") 

Inside a calculate this filter (TableB[Col1] = "Some Filter") translates to 

FILTER( ALL(TableB[Col1]), TableB[Col1] = "Some Filter") 

ALL removes any filter on Col1 and creates a new filter.

 

FILTER(TableB, TableB[Col1] = "Some Filter")

This is different

If there is any filter coming from outside, TableB will contains rows corresponding to that filter and that will intersect with filter "Some Filter".

In DAX Filters are tables.

 

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.