Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

YTD with selected value

Hi, I have a YTD measure that shows YTD values until the end of last month, and it works fine if no Year is selected, but if a previous  Year is selected in the slicer, the YTD value shows the whole...
  • Jihwan_Kim's avatar
    5 years ago

    Hi, Anonymous 

    Please try the below.

     

    YTD =
    VAR currentyear =
    MAX ( [yourcalendartable's year column] )
    VAR ActualMonthBeginning =
    DATE ( currentyear, MONTH ( TODAY () ), 01 )
    VAR YearBeginning =
    DATE ( YEAR ( MIN ( 'Date Table'[date] ) ), 01, 01 )
    RETURN
    CALCULATE (
    [sales total],
    FILTER (
    'Data',
    'Data'[Date] < ActualMonthBeginning
    && 'Data'[Date] >= YearBeginning
    )
    )

     

     

    Hi, My name is Jihwan Kim.

     

    If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

     

    Linkedin: linkedin.com/in/jihwankim1975/

    Twitter: twitter.com/Jihwan_JHKIM

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Jihwan_Kim , what I was trying to achieve is to have YTD last year
    And the following formula works well.

     

    YTD Last Year=

    VAR currentyear =

    MAX ( 'Date Table'[year])

    VAR ActualMonthBeginning =

    DATE ( currentyear, MONTH ( TODAY () ), 01 ) var LY= EDATE(ActualMonthBeginning,-12)

    RETURN

    CALCULATE (

    [sales total],SAMEPERIODLASTYEAR('Date Table'[Date]),

    'Date Table'[Date] < LY

     

    )