Forum Discussion
Measure is taking long time
6 Replies
- Bibiano_GeraldoSuper User
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_2023Helper IV
Than you very much for the quick response. I have tried, but still getting the error.
- Bibiano_GeraldoSuper User
Can you share a sample file with no sensitive information, please? anusha_2023
- rajendraongole1Super User
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.
- danextianSuper User
There doesn't seem to be much goin on with your measure. Now, how granular is the data in your viz?
- anusha_2023Helper IV
Data summarized to month level. This is the sample data