Forum Discussion
Need help with iterative measure
- 7 years ago
EDIT: Posted the below before seeing your post. Looks like you have a solution already.
Thanks for that :)
So you basically want to replace the return with zero for the first id in the context of the overall filters, but thereafter use the return from the table. You were on the right track with the code snippet you just posted, but I have defined min_id_allselected which gives the min_id for the current list (i.e. max_list).
This measure worked for me. There are potentially different ways you could write this but it should do the trick:
current_cumulative_return = VAR max_list = MAX ( 'CMC Daily Return'[list_id] ) VAR max_id = MAX ( 'CMC Daily Return'[id] ) VAR min_id_allselected = CALCULATE ( MIN ( 'CMC Daily Return'[id] ), 'CMC Daily Return'[list_id] = max_list, ALLSELECTED ( 'CMC Daily Return' ) ) RETURN CALCULATE ( PRODUCTX ( 'CMC Daily Return', 1 + IF ( 'CMC Daily Return'[id] = min_id_allselected, 0, 'CMC Daily Return'[daily_return] ) ), 'CMC Daily Return'[list_id] = max_list, 'CMC Daily Return'[id] <= max_id, ALLSELECTED ( 'CMC Daily Return' ) )Regards,
Owen
EDIT: Posted the below before seeing your post. Looks like you have a solution already.
Thanks for that :)
So you basically want to replace the return with zero for the first id in the context of the overall filters, but thereafter use the return from the table. You were on the right track with the code snippet you just posted, but I have defined min_id_allselected which gives the min_id for the current list (i.e. max_list).
This measure worked for me. There are potentially different ways you could write this but it should do the trick:
current_cumulative_return =
VAR max_list =
MAX ( 'CMC Daily Return'[list_id] )
VAR max_id =
MAX ( 'CMC Daily Return'[id] )
VAR min_id_allselected =
CALCULATE (
MIN ( 'CMC Daily Return'[id] ),
'CMC Daily Return'[list_id] = max_list,
ALLSELECTED ( 'CMC Daily Return' )
)
RETURN
CALCULATE (
PRODUCTX (
'CMC Daily Return',
1 + IF ( 'CMC Daily Return'[id] = min_id_allselected, 0, 'CMC Daily Return'[daily_return] )
),
'CMC Daily Return'[list_id] = max_list,
'CMC Daily Return'[id] <= max_id,
ALLSELECTED ( 'CMC Daily Return' )
)
Regards,
Owen
Haha! You posted your final one measure solution before I was finally able to figure it out. Thanks for helping me get there.
- dpc_development7 years ago
Helper III
Hi OwenAuger, can you please help me with another question?