Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
EktaSoni_R
Helper I
Helper I

Cummulative Sales calculation only for previous year.

Hello, 
I have tried to calculated only previous year cumulative sales, But unable to achive, i have tried n number of formulas but i am unable to get the output. Below dax is giving me till todays month data , i want restrict only for the last year. Any lead will be much appreciated.

LastYearAccumulativeRevenue =
CALCULATE(
SUM([amount]),
YEAR('Date'[Date]) = YEAR(TODAY())-1,
'Date'[Date]<= MAX('Date'[Date])
)

1 ACCEPTED SOLUTION

@EktaSoni_R 

Please try this:

YTD LY = 
    IF( YEAR( MAX( 'Date'[Date] ) ) = YEAR( TODAY()),
    
        CALCULATE(
            CALCULATE(
                [Sales Amount],
                DATESYTD( 'Date'[Date] )   
            ),
            SAMEPERIODLASTYEAR( 'Date'[Date] )
        )
    )
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

10 REPLIES 10
Fowmy
Super User
Super User

@EktaSoni_R 

Folow this pattern:

YTD LY = 
CALCULATE(
    CALCULATE(
        [Sales Amount],
        DATESYTD( 'Date'[Date] )   
    ),
    SAMEPERIODLASTYEAR( 'Date'[Date] )
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 
Above Dax is giving correct output while testing using the table view with date slicer, but the problem is when same i am using in Bar chart without any slicer, it is giving the all previous year data which is present in date table.

 My current requirement is there wont be any slicer for date, chart shows only for previous year cummulative value.

@EktaSoni_R 

I am not sure how you have used the measure on the bar chart. However, the basic idea is that you need to have a date in the x-axis it could be month, qtr or year, in the Y-axis add the this measure. 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy Thanks for the relpy, I have used the Mon-Year in X asix , you can see in the chart that it is showing for all the previous year, I just want to stick only to the last year.

EktaSoni_R_0-1701778986508.png

 

@EktaSoni_R 

In that case I need to now how you want the current year to be considered if you dont select any date from the date table. IS it fine take actual current year like 2023

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy  Yes actual current year - 2023 as current year.

Thanks 

@EktaSoni_R 

Please try this:

YTD LY = 
    IF( YEAR( MAX( 'Date'[Date] ) ) = YEAR( TODAY()),
    
        CALCULATE(
            CALCULATE(
                [Sales Amount],
                DATESYTD( 'Date'[Date] )   
            ),
            SAMEPERIODLASTYEAR( 'Date'[Date] )
        )
    )
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 

Thank you very much , It is working 😀

philouduv
Resolver III
Resolver III

Hello @EktaSoni_R,
I tried a little calculated column in a fake table that had 2 column, amount and date. 

Amountdate

104/12/2023
226/08/2023
318/05/2023
407/02/2023
530/10/2022
622/07/2022
713/04/2022
803/01/2022
925/09/2021
1017/06/2021


Hope it helps, if not you would need to give further details.
Formula: 

cumulative_sum_previous_year = CALCULATE(SUM(Table9[Amount]),
 Filter(Table9,
 Table9[date].[Year] < MAX(Table9[date].[Year])
 &&
 Table9[date].[Year] > MAX(Table9[date].[Year]) - 2
 ))
 

Best regards,

@philouduv ,

Thanks for the reply, but this solution is not working for me.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.