Forum Discussion

BrianNeedsHelp's avatar
BrianNeedsHelp
Icon for Resolver I rankResolver I
1 year ago
Solved

Same Period Last Year with Filter

I simply want to return results from last year based on the number of months that have passed this year.  So this year would be January through October have passed.   I want to get last years results January through October, so I'm trying to filter using MAX Calendar Date.   This below is not working and is computing the results of this year and not last year.  

GA LY = CALCULATE([Gross Adds],FILTER('Calendar','Calendar'[CalendarDate]=MAX([Calendar Date],SAMEPERIODLASTYEAR('Calendar'[Calendar Date]))))

 

  • lbendlin's avatar
    lbendlin
    1 year ago
    GA LY = var m = max('Calendar'[CalendarDate]) return CALCULATE([Gross Adds],SAMEPERIODLASTYEAR('Calendar'[Calendar Date]),'Calendar'[Calendar Date]<=EDATE(m,-12))
  • BrianNeedsHelp's avatar
    BrianNeedsHelp
    1 year ago

    lbendlin  Found this on Marc Russo's blog, if anyone needs a solution.  This works:  

    PY Last Day Selection = VAR LastDaySelection =     LASTNONBLANK ( 'Calendar'[Calendar Date], [Gross Adds] ) VAR CurrentRange =     DATESBETWEEN ( 'Calendar'[Calendar Date], MIN ( 'Calendar'[Calendar Date] ), LastDaySelection ) VAR PreviousRange =     SAMEPERIODLASTYEAR ( CurrentRange ) RETURN     IF (         LastDaySelection > MIN ( 'Calendar'[Calendar Date]),CALCULATE ( [Gross Adds], PreviousRange ))

     

10 Replies

  • GA LY = var m = max('Calendar'[CalendarDate]) return CALCULATE([Gross Adds],SAMEPERIODLASTYEAR('Calendar'[Calendar Date]),MONTH(MAX('Calendar'[Calendar Date]))<=MONTH(m))
    • BrianNeedsHelp's avatar
      BrianNeedsHelp
      Icon for Resolver I rankResolver I

      lbendlin  Hi-I'm getting "The true/false expression does not specify a column. Each true/false expression used as a table filter expression must refer to exactly one column".  

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User
        GA LY = var m = max('Calendar'[CalendarDate]) return CALCULATE([Gross Adds],SAMEPERIODLASTYEAR('Calendar'[Calendar Date]),'Calendar'[Calendar Date]<=EDATE(m,-12))
  • YES!   After hours of trying differen things.  This is amazing.  THANK YOU! 

  • Hi lbendlin I thought it was working, but it only works if I filter the months in a slicer.  Otherwise it still counts the whole year.  I've run into this problem on several ideas I've tried.  Do you know how I can get it to just calculate based on Max date of this current year?