Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Cumulative sum that resets every year

Hi, 

I guess my question is simple, I want a cummlative sum that resets every year. I went through almost all the threads here and tried the formulas with no luck. Here is a sample of my data. The formula I used is:

 

 

Cumm.approved= 
VAR __year = MAX(projectTrendingData[Date].[Year])
RETURN
CALCULATE(
SUM (projectTrendingData[Approved]),
filter(
all(projectTrendingData),
projectTrendingData[Date]<=max(projectTrendingData[Date]) && YEAR([Date]) = __year))

 

 

 

I simply want to produce the cummulative sum for the Approved column and get it to reset every year.

DateApprovedCumm.approved
Thursday, January 3, 20194 
Thursday, January 17, 20191 
Thursday, January 31, 20197 
Thursday, February 14, 20196 
Thursday, February 28, 20199 
Thursday, March 14, 201913 
Thursday, March 28, 201919 
Thursday, April 11, 20199 
Thursday, April 25, 201910 
Thursday, May 9, 201916 
Thursday, May 23, 20196 
Thursday, June 6, 20196 
Thursday, June 20, 20199 
Wednesday, July 3, 201917 
Thursday, July 18, 20199 
Thursday, August 1, 201920 
Thursday, August 15, 20199 
Thursday, August 29, 201918 
Thursday, September 12, 20199 
Thursday, September 26, 201913 
Thursday, October 10, 201913 
Thursday, October 24, 201911 
Thursday, November 7, 201915 
Thursday, November 21, 201919 
Thursday, December 5, 201920 
Thursday, December 19, 201922 
Thursday, January 2, 202013 
Thursday, January 16, 202017 
Thursday, January 30, 202027 
Wednesday, February 5, 202020 
Thursday, February 27, 202013 
Thursday, March 12, 202034 
Sunday, March 29, 202023 
  • Hi Anonymous ,

    I create a sample. Please have a try to check if it is what you want.

    • Create a year column
    Year = YEAR('Table'[Date])
    •  Create a measure
    Measure =
    CALCULATE (
        SUM ( 'Table'[Approved] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] <= MAX ( 'Table'[Date] )
                && 'Table'[Year] = MAX ( 'Table'[Year] )
        )
    )
    

11 Replies

  • v-xuding-msft's avatar
    v-xuding-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

    I create a sample. Please have a try to check if it is what you want.

    • Create a year column
    Year = YEAR('Table'[Date])
    •  Create a measure
    Measure =
    CALCULATE (
        SUM ( 'Table'[Approved] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] <= MAX ( 'Table'[Date] )
                && 'Table'[Year] = MAX ( 'Table'[Year] )
        )
    )
    

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-xuding-msft 

       

      Thank you, this solution was the simplest and it fit my case. I am amazed with how poeple are helpful here

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        Anonymous , Looking at marked solution. You seems to have marked the message to wrong person 😀

    • Anonymous's avatar
      Anonymous
      Not applicable

      This is excellent!  You just solved my problem, as well!  Thank you.  😉

  • edhans's avatar
    edhans
    Icon for Community Champion rankCommunity Champion

    Read this fantastic article by SQLBI. It is about hiding future dates, but you can use the exact same concept. You just need a field in your Date table that is [IsCurrentYear] which just returns true or false if the year of the [Date] field is the same as the current year based on Today() if using a Calculated Column in DAX or DateTime.LocalNow() if using Power Query for your date table.

     

    Then you just filter per that article on your IsCurrentYear field. I have one for the current year, quarter, week, month, etc for all sorts of easy measures and slicers.

     

    By the way, you really need a true date table for this. See Creating a Dynamic Date Table in Power Query to create one in Power Query. You cannot add these fields to the automatic date table, which I can tell you are using based on your measure.

  • Anonymous ,

    You need to use YTD. YTD resets every year. Use the Date calendar with this

     

    YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
    This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))
    

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
    https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
    https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
    https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

  • ImkeF's avatar
    ImkeF
    Icon for Community Champion rankCommunity Champion

    Hi Anonymous  

    your formula should principally work as a measure. Or do you want to create a calculated column to your table?

    Just be aware of the column you're referencing, as it is "[Approved During the 2 Week Reporting Period]" in your formula and plain "Approved" in the sample data you've given.