Forum Discussion

anusha_2023's avatar
anusha_2023
Helper IV
1 year ago

Measure is taking long time

Hi! Please advise me on how to optimize the measures:
When I am calculating for rollingmonths If Reference date is EOMONTH(TODAY(),-1) then Calculation is very quick instead if I am replacing with 
EOMONTH(
CALCULATE(
    MAX(RevenuePerHourView[VoucherDate]),
    RevenuePerHourView[TotalQuantity] > 0), -1)
In this case measure is taking so long and almost impossible to get data.
I have placed both measures here. Preferably I need to optimize the second measure to get the date as where Quantity column is greater than 0 and make the calculation. 
Any optimization techniques to improve this simple measure
Hour Rolling Months Matrix Measure 1 =
CALCULATE(
    SUM(RevenuePerHourView[TotalQuantity]),
    DATESINPERIOD(
        'Date'[Date],
        EOMONTH(TODAY(),-1),
        -SELECTEDVALUE(RollingMonthsParameter[RollingMonthsParameter]),
        MONTH
    ))
 
 
Hour Rolling Months Matrix Measure 2=
CALCULATE(
    SUM(RevenuePerHourView[TotalQuantity]),
    DATESINPERIOD(
        'Date'[Date],
        EOMONTH(
CALCULATE(
    MAX(RevenuePerHourView[VoucherDate]),
    RevenuePerHourView[TotalQuantity] > 0), -1),
        -SELECTEDVALUE(RollingMonthsParameter[RollingMonthsParameter]),
        MONTH
    ))

6 Replies

  • Hi anusha_2023 ,
    The issue lies in the use of CALCULATE inside EOMONTH, which can significantly slow down performance. This happens because it evaluates the entire table repeatedly.

    you can try to use variables like bellow measure:

    Hour Rolling Months Matrix Measure 2 =
    VAR MaxVoucherDate =
        CALCULATE(
            MAX(RevenuePerHourView[VoucherDate]),
            RevenuePerHourView[TotalQuantity] > 0
        )
    VAR TargetDate = EOMONTH(MaxVoucherDate, -1)
    RETURN
        CALCULATE(
            SUM(RevenuePerHourView[TotalQuantity]),
            DATESINPERIOD(
                'Date'[Date],
                TargetDate,
                -SELECTEDVALUE(RollingMonthsParameter[RollingMonthsParameter]),
                MONTH
            )
        )

     

     



    • anusha_2023's avatar
      anusha_2023
      Helper IV

      Than you very much for the quick response. I have tried, but still getting the error.

       

  • Hi anusha_2023 - can you please try the below approach and also test it via performance analyzer.

     

    Hour Rolling Months Matrix Measure 2 =
    VAR FilteredTable =
    FILTER(
    RevenuePerHourView,
    RevenuePerHourView[TotalQuantity] > 0
    )
    VAR RefDate =
    MAXX(
    TOPN(
    1,
    FilteredTable,
    RevenuePerHourView[VoucherDate], DESC
    ),
    RevenuePerHourView[VoucherDate]
    )
    RETURN
    IF(
    ISBLANK(RefDate),
    BLANK(), // Handle case where no valid Reference Date exists
    CALCULATE(
    SUM(RevenuePerHourView[TotalQuantity]),
    DATESINPERIOD(
    'Date'[Date],
    EOMONTH(RefDate, -1),
    -SELECTEDVALUE(RollingMonthsParameter[RollingMonthsParameter]),
    MONTH
    )
    )
    )

     

    The above optimized version above refines it slightly for edge cases and readability.

     

    Hope this helps.

  • There doesn't seem to be much goin on with your measure. Now, how granular is the data in your viz?

    • anusha_2023's avatar
      anusha_2023
      Helper IV

      Data summarized to month level. This is the sample data