Forum Discussion

SR11's avatar
SR11
Frequent Visitor
5 years ago
Solved

Optimize measure

Hi, I have a lot of measures on my report to calculate totals by the max date. Here is one of my measure-     mUnitsTotal = VAR MaxTable = ADDCOLUMNS( SUMMARIZE('Sales','Sales'[Job],'S...
  • v-cazheng-msft's avatar
    5 years ago

    Hi SR11 

    The performance of EARLIER might be slow, depending on the syntax of the expression, it may perform multiple operations. For example if you have 10 rows in the column, approximately a 100 operations could be required. Therefore, It should be avoided as much as possible. You can try this Measure as its replace.

     

    mUnitsTotal =
    
    VAR max_date =
    
        ADDCOLUMNS (
    
            Sales,
    
            "max_date",
    
                CALCULATE (
    
                    MAX ( Sales[EntryDates] ),
    
                    ALLEXCEPT ( Sales, Sales[Job], Sales[SubJob] )
    
                )
    
        )
    
    VAR mTotal =
    
        SUMX ( FILTER ( max_date, [max_date] = [EntryDates] ), [Unit Total] )
    
    RETURN
    
        IF ( HASONEFILTER ( Sales[EntryDates] ), MAX ( Sales[Unit Total] ), mTotal )

     

    The result looks like this:

     

    For more details, you can refer the attached pbix file.

     

    Best Regards

    Caiyun Zheng

     

    If this post helps, please consider make it as the solution by Accept it as Solution. Really appreciate!