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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
gabcass
New Member

Measure to calculate current and previous year cumulative sales on monthly basis

Hi,

I am trying to calculate the cumulative sales for the current year and also the previous year, with the ability to filter the data by year through a slicer.

 

I'm struggling because when the slicer is set for 2025, I can't display the previous year's sales for all months.

The following measure is not working:

 

Cumulative Sales Previous Year = CALCULATE(TOTALYTD([Sales], DATEADD(DimDate[Date], -365, DAY)))

My data model has a date table connected to a sales table via the date column.

 

How can I display the previous year's cumulative sales for all months when the slicer is filtering for the current year?

Thanks in advance!

 

 

 

 

10 REPLIES 10
sjoerdvn
Super User
Super User

Hi there,

The issue might not be the DAX, as the previous answers look OK. Are you sure that in your report context you actually have all dates for 2025? It might be that your date dimension does not have dates beyond today or that there is another filter active that filters out dates beyond today.  If that's the case then that would cause SAMEPERIODLASTYEAR and comparable solutions to not work.
You can test that by creating dummy measure that returns a fixed value and adding that to the visual. It should return that value for each month.

Hi @sjoerdvn 

 

Actually I don't have all dates for 2025 beyond today in my date dimention. I'll include them and test if the recommended measures work. Thanks.

Anonymous
Not applicable

Hi @gabcass ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

govind_021
Super User
Super User

Hi @gabcass 
You can create two separeate measures
Cumulative Sales Current Year =
TOTALYTD(
[Sales],
DimDate[Date]



Cumulative Sales Previous Year =
CALCULATE(
TOTALYTD(
[Sales],
DimDate[Date]
),
SAMEPERIODLASTYEAR(DimDate[Date])
)

Use both in the visual

Hi @govind_021, thanks for your help.

 

The issue is that I have a slicer for year. The measure you suggested works well if I select previous years in my slicer:

GabeCass_0-1736940597725.png

 

However if I select 2025 the visual displays data for January only:

GabeCass_1-1736940803969.png

and this is OK for the current year, since we are in January, but actually I'd like the visual to display the previous year sales across all months, even if I'm slicing it for 2025.

 

Do you have any idea about how can I solve this?

 

Regards!

 

Anonymous
Not applicable

Hi @gabcass ,

Any update on this? Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

lbendlin
Super User
Super User

You need to add another filter.

Cumulative Sales Previous Year =
CALCULATE (
    [Sales],
    SAMEPERIODLASTYEAR ( DimDate[Date] ),
    DimDate[Date] <= EDATE ( TODAY (), -12 )
)

 

Hi @lbendlin, thanks for your help.

 

The measure you suggested gives returns the cumulative sales in the previous year in this exact date.

 

GabeCass_2-1736941301294.png

 

My goal here is to display the current and previous year cumulative sales across all months, regardless of the year I'm slicing, like the image below:

 

GabeCass_3-1736941414981.png

 

But for 2025 as well.

GabeCass_4-1736941546831.png

 

 

Any clue on how can I achieve this?

 

Thanks!

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

DAX (CALENDAR(DATE(2023,01,01),DATE(2025,12,31))

The table is marked as as date table:

Dim Date

DateMonthYearDateWithSales
01/01/2023Jan2023True
02/01/2023Jan2023True
......... 
31/12/2025Jan2025False

 

FactSales

OrderDateProductKeyQtyUnitValueTotalSales
10/01/20237001873005.751,725.00
...............
20/01/202540040221,268.002537.50

There is a one-to-many relationship between DimDate[Date] and FactSales[OrderDate]

 

In the Report View, there is a dropdown slicer for Date[Year] set for single selection:

 

The Goal:

I want to project two line charts:

One displaying current year and previous year monthly sales;

One displaying current year and previous year cumulative monthly sales.

 

Additional Details:

I am referring as the current year as the year set in the slicer, therefore according to the year selected I expect the charts to be updated automatically.

When slicing 2025, I don't want to display current year's sales for further months later to today's date as $0, having the line related to current year's sales displayed up to today's date month.

 

 

Measures Used:

 

Total Sales (measure used to compute current year sales and to calculate the other measures) =

VAR _Sales = CALCULATE(SUM('FactSales'[TotalSales]))
RETURN
IF(_Sales=0,0,_Sales)

 

Previous Year Sales = 

CALCULATE([Total Sales],DATEADD(DimDate[Date],-1,YEAR))

 

Cumulative Sales =

CALCULATE(TOTALYTD(
[TotalSales],
DimDate[Date],DimDate[Date]<=TODAY()),
CALCULATETABLE(DATESYTD ('DimDate'[Date]),'DimDate'[DateWithSales]= TRUE))

 

Previous Year Cumulative Sales  =

CALCULATE(
TOTALYTD(
[Total Sales],
DimDate[Date]
),
SAMEPERIODLASTYEAR(DimDate[Date])
)

 

Considering the scenario above, I've almost completed my goal, with the exception that in both charts I'm still displaying current year's monthly sales as zero for months later to today's date.

 

Do you have any work around for this?

 

P.S.: I'm not being able to select accept any answer as a solution. Could you explain me how can I do that?

 

Thanks in advance.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.