Forum Discussion

dpc_development's avatar
dpc_development
Helper III
7 years ago
Solved

Need help with iterative measure

I have a model with three columns - list_id, sequence, daily_return. Basically, for each list_id, there is a sequence of numbers from 0 onwards (0, 1, 2, ..., X) with different percentage values in ...
  • OwenAuger's avatar
    OwenAuger
    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