Forum Discussion

andyln33's avatar
andyln33
Frequent Visitor
6 years ago
Solved

Cumulative Count Previous Year

https://imgur.com/akzvvqU 

 

Cumlative count is displaying great for this year. But how do I go about showing the previous year? You can see in the screenshot above I'm looking to compare 2 years, cumulatively.  (This YTD, and last year entirely)

 

CUMULATIVE = CALCULATE(
COUNT ( IncidentInjury[id] ),
FILTER (
ALLSELECTED ( IncidentInjury ),
IncidentInjury[created_at] <= MAX ('IncidentInjury'[created_at] )
))
  • This is your code:

    Cum2 = TOTALYTD(CALCULATE(COUNT(IncidentInjury[id]));IncidentInjury[created_at];ALL(IncidentInjury))
    Cum3 = TOTALYTD(CALCULATE(COUNT(IncidentInjury[id]));SAMEPERIODLASTYEAR(IncidentInjury[created_at]);ALL(IncidentInjury))

    as seen here:

    Please mark as solution if so, thumbs up for the effort would be great.

    Kind regards, Steve. 

5 Replies

  • SAMEPERIODLASTYEAR() gives you the entire previous year's date range. That is somewhat unexpected, but it perfectly fits what you want (however questionable the reasoning behind that is).

  • stevedep's avatar
    stevedep
    Icon for Memorable Member rankMemorable Member

    This is your code:

    Cum2 = TOTALYTD(CALCULATE(COUNT(IncidentInjury[id]));IncidentInjury[created_at];ALL(IncidentInjury))
    Cum3 = TOTALYTD(CALCULATE(COUNT(IncidentInjury[id]));SAMEPERIODLASTYEAR(IncidentInjury[created_at]);ALL(IncidentInjury))

    as seen here:

    Please mark as solution if so, thumbs up for the effort would be great.

    Kind regards, Steve. 

    • andyln33's avatar
      andyln33
      Frequent Visitor

      Thanks Steve!

       

      What's the filter/syntax to cut the data off at the MAX date? (For example, I want the line to stop at June)

       

       

       

       

       

       

      • stevedep's avatar
        stevedep
        Icon for Memorable Member rankMemorable Member

        Welcome! 

        Are you using a date dimension?