Forum Discussion
Optimisation - Context transition in iterator
- 2 years ago
Can you try the following :
VAR CurrentInterval =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_END_DATE] )
VAR StartDate =
SELECTEDVALUE( 'RLS CALENDAR'[YEAR_START_DATE] )
VAR Grain =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_GRAIN] )
VAR Selected_Territory =
SELECTEDVALUE ( 'RLS CALENDAR'[TERRITORY_CODE] )
VAR calculate_volume =
CALCULATE (
[Total volume],
FILTER (
ALL ( 'RLS CALENDAR' ),
'RLS CALENDAR'[LEVEL_1_END_DATE] > StartDate
&& 'RLS CALENDAR'[LEVEL_1_END_DATE] <= CurrentInterval
&& 'RLS CALENDAR'[LEVEL_1_GRAIN] = Grain
&& 'RLS CALENDAR'[TERRITORY_CODE] = Selected_Territory
)
)
RETURN
calculate_volume
===============OR===================
VAR CurrentInterval =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_END_DATE] )
VAR StartDate =
SELECTEDVALUE( 'RLS CALENDAR'[YEAR_START_DATE] )
VAR Grain =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_GRAIN] )
VAR Selected_Territory =
SELECTEDVALUE ( 'RLS CALENDAR'[TERRITORY_CODE] )
RETURN
SUMX (
FILTER (
ALL ( 'RLS CALENDAR' ),
'RLS CALENDAR'[LEVEL_1_END_DATE] > StartDate
&& 'RLS CALENDAR'[LEVEL_1_END_DATE] <= CurrentInterval
&& 'RLS CALENDAR'[LEVEL_1_GRAIN] = Grain
&& 'RLS CALENDAR'[TERRITORY_CODE] = Selected_Territory
),
[Total volume]
)
The above two expressions calculate the Total volume measure outside of the iteration and place it in a variable. These should help improve performance by reducing the number of iterations required to calculate the expression.
You can read Marco Russo's article on optimizing DAX expressions:
https://www.sqlbi.com/articles/optimizing-dax-expressions-involving-multiple-measures/
Please let me know if this help.
Thanks
Babatunde Dallas
Can you try the following :
VAR CurrentInterval =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_END_DATE] )
VAR StartDate =
SELECTEDVALUE( 'RLS CALENDAR'[YEAR_START_DATE] )
VAR Grain =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_GRAIN] )
VAR Selected_Territory =
SELECTEDVALUE ( 'RLS CALENDAR'[TERRITORY_CODE] )
VAR calculate_volume =
CALCULATE (
[Total volume],
FILTER (
ALL ( 'RLS CALENDAR' ),
'RLS CALENDAR'[LEVEL_1_END_DATE] > StartDate
&& 'RLS CALENDAR'[LEVEL_1_END_DATE] <= CurrentInterval
&& 'RLS CALENDAR'[LEVEL_1_GRAIN] = Grain
&& 'RLS CALENDAR'[TERRITORY_CODE] = Selected_Territory
)
)
RETURN
calculate_volume
===============OR===================
VAR CurrentInterval =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_END_DATE] )
VAR StartDate =
SELECTEDVALUE( 'RLS CALENDAR'[YEAR_START_DATE] )
VAR Grain =
SELECTEDVALUE ( 'RLS CALENDAR'[LEVEL_1_GRAIN] )
VAR Selected_Territory =
SELECTEDVALUE ( 'RLS CALENDAR'[TERRITORY_CODE] )
RETURN
SUMX (
FILTER (
ALL ( 'RLS CALENDAR' ),
'RLS CALENDAR'[LEVEL_1_END_DATE] > StartDate
&& 'RLS CALENDAR'[LEVEL_1_END_DATE] <= CurrentInterval
&& 'RLS CALENDAR'[LEVEL_1_GRAIN] = Grain
&& 'RLS CALENDAR'[TERRITORY_CODE] = Selected_Territory
),
[Total volume]
)
The above two expressions calculate the Total volume measure outside of the iteration and place it in a variable. These should help improve performance by reducing the number of iterations required to calculate the expression.
You can read Marco Russo's article on optimizing DAX expressions:
https://www.sqlbi.com/articles/optimizing-dax-expressions-involving-multiple-measures/
Please let me know if this help.
Thanks
Babatunde Dallas