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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
masplin
Impactful Individual
Impactful Individual

Filter vs CALCULATETABLE

is question was asked last year, but the answer doesn't actually help me

 

I have only ever used FILTER when trying to find values in other tables. I can see i'm missing a trick and at times using CALCULATE table woul be more efficient.  My question is when is this the case? it seems to be related to cardinality

 

Below is a particularly horrible example where I am trying to locate the first ranked VRM on a large 'Posted Document Table" from smaller 'MOTLeads' table. 

 

In terms of cardniality on the big table there are 100,000 differnet VRMs, the dates only over 90 days out of the 400 days in the full table, Inc MOT is 0 or 1. So for this example would CALCULATE table be better to create this small outer filter with just one row in it, and CALCULATE table in the inner part produces a few rows with all the occurrences of that VRM in the date range   ?

 

I suspect the answer is "depends" and I need ot measure the speed. i have no idea how to do that. Is this a tool in DAX Studio or something . Is there a tuturial on measuring the speed of calculations?

 

Thnaks

Mike

 

   CALCULATE(
                           VALUES('Posted Document Header'[Document No]),
                          FILTER('Posted Document Header',
                                         'Posted Document Header'[VRM]=MOTLeads[VRM]  &&
                                         'Posted Document Header'[Posting Date]>[MOT Due Date]-35 &&
                                          'Posted Document Header'[Posting Date]<[MOT Due Date]+60 &&
                                         'Posted Document Header'[Inc MOT]>0 &&
                                          'Posted Document Header'[Rank Vehicle Visit]=CALCULATE(
                                                                                                                                    MIN('Posted Document Header'[Rank Vehicle Visit]),
                                                                                                                                    FILTER('Posted Document Header',
                                                                                                                                                   'Posted Document Header'[VRM]=MOTLeads[VRM]  &&
                                                                                                                                                   'Posted Document Header'[Posting Date]>[MOT Due Date]-35 &&
                                                                                                                                                   'Posted Document Header'[Posting Date]<[MOT Due Date]+60 &&
                                                                                                                                                    'Posted Document Header'[Inc MOT]>0
                                                                                                                                                    )
                                                                                                                                     )                                                                                )
                              )

 

2 REPLIES 2
Greg_Deckler
Super User
Super User

Not sure this is answering your question but using FILTER versus CALCULATETABLE are quite different and I think it depends on your use. For example, when you use CALCULATE with a FILTER, you can use functions like SUM, COUNT, etc. but to get the equivalent with CALCULATETABLE you would have to preface that function with something like a SUMX, COUNTX, etc. and this is generally going to be slower than their equivalent, non-X, versions of those functions.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

I tried a little experiement and also witrh FILTER you can do Table1[Field1]=Table2[Field1] like I have but doesnt work for CALCULATETABLE.  

 

Maybe CALCULATETABLE is good if you just want sinmple filters like item="red"

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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