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
zazaalaza
Frequent Visitor

DAX too Slow with Filtering

Hi,

I have the following measure:

Measure = 
    CALCULATE ( 
        COUNT ( 'Table'[Value] ), 
        FILTER ( 
            ALL ( 'Table' ), 
            'Table'[ValidFromDate] < MAX ( 'Date'[Date] ) && 
            'Table'[ValidToDate] > MAX ( 'Date'[Date] ) 
        ) 
    )


The two tables (Table, Date) are not connected.

I use this to see "Active" contracts on a specific date. However when I place it in a visual to see it on a daily basis (last 12 months for example), it is way too slow (I have 12 million rows). 

Is there a way to optimize this?
Much appreciated!

4 REPLIES 4
zazaalaza
Frequent Visitor

Perhaps there is a way to make it faster without using Calculate? @Greg_Deckler Any ideas? 

Yeah, I have seen this pattern be slow occasionally.

Without CALCULATE can be written fairly similarly.

Measure =
VAR _MaxDate = MAX ( 'Date'[Date] )
RETURN
    COUNTROWS (
        FILTER (
            ALL ( 'Table' ),
            'Table'[ValidFromDate] < _MaxDate &&
            'Table'[ValidToDate]   > _MaxDate
        )
    )
AlexisOlson
Super User
Super User

It might help to make the max date a variable.

Measure =
VAR _MaxDate = MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        COUNT ( 'Table'[Value] ),
        ALL ( 'Table' ),
        'Table'[ValidFromDate] < _MaxDate,
        'Table'[ValidToDate] > _MaxDate
    )

Thanks but that doesn't help.

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.