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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
zervino
Helper I
Helper I

DAX measure for previous year/month value

I have a table with 5 columns:

 

PlanYearMonthYear/MonthSales
2024 FC202401202401100
2024 FC20240220240275
2024 Actuals202401202401120
2025 FC202501202501105
2025 Actuals202501202501140

 

I want to add a measure to show the value of the same period but previous year/month. For example from previous table:

 

PlanYearMonthYear/MonthSalesPrevious Sales
2024 FC202401202401100 
2024 FC20240220240275 
2024 Actuals202401202401120 
2025 FC202501202501105120
2025 Actuals202501202501140120

 

I use the current formula:

Previous Sales = 
CALCULATE([Sales],
    FILTER(
        ALL('Dates'),
            'Dates'[Month]=SELECTEDVALUE('Dates'[Month])
    ),
    'Dates'[Year]=SELECTEDVALUE('Dates'[Year]) - 1
)

 

* I have joined my fact table to a 'Dates' table on Year/Month column.

 

The formula works, the problem is that when I create a visual of a table and I filter by year "2025 Actuals" only, the Previous Sales column appears empty. It only gets populated if I also have "2024 Actuals" included.

 

Is there a way to avoid having to include the previous year?

1 ACCEPTED SOLUTION

pls try

Previous Sales = 
VAR _LasttYear =  SELECTEDVALUE('Dates'[Year]) - 1
VAR _CurrentMpnth  =  SELECTEDVALUE('Dates'[Month])
RETURN

CALCULATE([Sales], 
  'Dates'[Month]=_CurrentMpnth&&
    'Dates'[Year]=_LasttYear,
REMOVEFILTERS()
)

View solution in original post

6 REPLIES 6
ahmedoye
Responsive Resident
Responsive Resident

I see, you can create date columns as Calculated columns from what you have and use CALCULATE([Sales], SAMEPERIODLASTYEAR(Dates[Date])). 

You can create column in your Sales Table as 

DateNew = DATE(VALUE(LEFT(Table1[Year],4)), VALUE(RIGHT(Table1[Year/Month])),1)
Then create Date Column in your Date table as 
DateCol = DATE('Date'[Year], 'Date'[Month], 1)

Then use those 2 columns to define the relationship between both tables and rewrite your measure with CALCULATE and SAMEPERIODLASTYEAR as I have indicated above.
ahmedoye
Responsive Resident
Responsive Resident

The best way to do this will be to have a Date Column (with date format) in your Sales Table. And then let it be related to the Date Column in your Date Table.

Then you can write your formula as CALCULATE([Sales], PREVIOUSMONTH(Dates[Date]))

If this works for you, kindly mark as answer to allow anyone with similar issues find the solutions quicker.

I don't have Date per se, I have year and month columns.

I need the sales of the same month, but for previous year for a specific plan (eg. Actuals, Forecast)

Ahmedx
Super User
Super User

pls try this

Previous Sales = 
VAR _LasttYear =  SELECTEDVALUE('Dates'[Year]) - 1
VAR _CurrentMpnth  =  SELECTEDVALUE('Dates'[Month])
RETURN

CALCULATE([Sales], 
  'Dates'[Month]=_CurrentMpnth&&
    'Dates'[Year]=_LasttYear
)

The result appears blank 😞

pls try

Previous Sales = 
VAR _LasttYear =  SELECTEDVALUE('Dates'[Year]) - 1
VAR _CurrentMpnth  =  SELECTEDVALUE('Dates'[Month])
RETURN

CALCULATE([Sales], 
  'Dates'[Month]=_CurrentMpnth&&
    'Dates'[Year]=_LasttYear,
REMOVEFILTERS()
)

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.