Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

How can I refactor my DAX cumulative code which is extremely slow

I have written this DAX code which calculates the cumulative total, however, it is extremely slow when I drill down from monthYear to a daily granularity.

 

partnerSignUpsCumulative = 
VAR MaxDate = MAX ( Leads[createddate] ) 
RETURN
    CALCULATE (
        [partnersSigned],            
        FILTER ( ALLSELECTED (Leads),
        Leads[createddate] <= MaxDate            
        )

 

 

 

 

Is there a way to refactor this code to make it perform faster?

2 Replies

  • Anonymous 

    The first item that jumps out at me is, you don't want to FILTER over a whole table.  Does this help the speed?

     

    partnerSignUpsCumulative = 
    VAR MaxDate = MAX ( Leads[createddate] ) 
    RETURN
        CALCULATE (
            [partnersSigned],            
            FILTER ( ALLSELECTED (Leads[createddate]),
            Leads[createddate] <= MaxDate            
            )

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Doing that makes it not a cumulative total anymore, it stops accumulating over each day rather it just shows the total for each specific day rather than carrying it over