Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

YTD Calculation

Hi,   I have Data Like Below.In the data i have 3 years of data and for 2019 i have only upto Oct, values but i have Months Nov & Dec as null .Now i need to calculate YTD which is only upto Oct 201...
  • v-lili6-msft's avatar
    6 years ago

    hi  Anonymous 

    For your case "calculate YTD which is only upto Oct 2019", you could try one of these three measures:

    Step1:

    Add a Month No column and  a Year-Month column

    Step2:

    Just try this measure formula

     

    Measure 1 = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Year]=MAX('Table'[Year])&&'Table'[Month No]<=MAX('Table'[Month No])))

     

    or this logic:

     

    Measure 2 = 
    var _maxyearmonth=CALCULATE(MAX('Table'[Year-Month]),FILTER(ALL('Table'),'Table'[Value]<>BLANK())) return
    var _maxmonthnoofmaxyear=CALCULATE(MAX('Table'[Month No]),FILTER(ALL('Table'),'Table'[Year-Month]=_maxyearmonth)) return
    IF(MAX('Table'[Month No])<=_maxmonthnoofmaxyear, CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Year]=MAX('Table'[Year])&&'Table'[Month No]<=MAX('Table'[Month No]))))

     

    or this ogic:

     

    Measure 3 = 
    var _maxyearmonth=CALCULATE(MAX('Table'[Year-Month]),FILTER(ALL('Table'),'Table'[Value]<>BLANK())) return
    IF(MAX('Table'[Year-Month])<=_maxyearmonth, CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Year]=MAX('Table'[Year])&&'Table'[Month No]<=MAX('Table'[Month No]))))

     

    Result:

     

    and here is sample pbix file, please try it.

     

    Regards,

    Lin