Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Converting YTD to MTD based on two variables

Hello,

 

I need to extract the monthly movement from the YTD based on two variables - the entity and LOB (line of business). The values are not available on a montly basis. 

Below is a sample of the data table

 

 

I tried to use this from another solution but it doesnt work?

 

Monthly Amount New = 
VAR _PDATE = 

CALCULATE(
    MAX('dataset'[Date]),
    CALCULATETABLE(
        ALLSELECTED('dataset'), 
        'dataset'[Product]=('dataset'[Product]),
        'dataset'[Entity] = ('dataset'[Entity]),
        'dataset'[Date]< EARLIER('dataset'[Date])
    )
)

VAR _PYTD = 

CALCULATE( MAX('dataset'[YTD Value]),
    CALCULATETABLE(
        ALLSELECTED('dataset'), 
        'dataset'[Product]=EARLIER('dataset'[Product]),
        'dataset'[Entity] = EARLIER('dataset'[Entity]),
        'dataset'[Date] =  _PDATE
    )
)

VAR YR =YEAR(_PDATE)
VAR CYR =YEAR('dataset'[Date])
RETURN
IF(
    YR < CYR,
    [YTD Value],
    [YTD Value] - _PYTD
)

 Thanks for your help

Kerry

3 Replies

  • Anonymous , Try a new column like

    Monthly Amount New =
    VAR _max = maxx(Filter('dataset'[Product]=('dataset'[Product]) && 'dataset'[Entity] = ('dataset'[Entity]) && 'dataset'[Date]< EARLIER('dataset'[Date])),'dataset'[Date])
    return
    [Value] - maxx(Filter('dataset'[Product]=('dataset'[Product]) && 'dataset'[Entity] = ('dataset'[Entity]) && 'dataset'[Date] =_max),'dataset'[Value])

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  amitchandak

    I have tried your suggested solution but it still doesnt work I'm afraid.


     

  • Hi, Anonymous 

    Could you please consider sharing more details about it and posting expected result so it is clear on what needs to be implemented?  And It would be great if there is a sample file without any sesentive information here.

    It makes it easier to give you a solution.

    1. Sample (dummy dataset) data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

     

    Best Regards,
    Community Support Team _ Zeon Zheng

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.