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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
SGBaringa
Frequent Visitor

Previous year value based on year integer slicer

Hello PBI Community,

 

I am having a hard time trying to figure out a solution for a seemilngly simple case.

 

What I have are two tables, Calendar and Sales. Calendar contains only one column which has unique integer numbers which represent years. The table Sales contains two columns, one is Periods which has multiple integer numbers for years, and Revenue which contains the revenue for the year.

Calendar:

Year

2024

2025

Sales:

PeriodRevenue
2024100
2024100
2025200
2025200

The two tables are connected via the Year to Period relationship which is a 1:*.

 

What I am trying to achieve is to have a slicer for the Year from the Calendar table on the page and when I select a specific year, for another visual to show me the previous year values for the Revenue from Sales.

 

For example, if I select 2025 on the slicer, I should get back 200 based on the tables I have shown above.

 

I am currently using this formula:

PreviousYearValue =
     VAR SelectedYear = SELECTEDVALUE('Calendar'[Year])
     VAR PreviousYear = SelectedYear - 1
RETURN
CALCULATE(
     SUM('Sales'[Revenue]),
          'Sales'[Year] = PreviousYear
)

The issue is that when I select a year, it gives me blank. 

 

Any help would be apprecated! Thank you!

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @SGBaringa - you are getting that issue because of the filter context applied on slicer calender entity.

 

can you check the below formaule:

PreviousYearRevenue =
VAR SelectedYear = SELECTEDVALUE('Calendar'[Year])
VAR PreviousYear = SelectedYear - 1
RETURN
CALCULATE(
SUM('Sales'[Revenue]),
'Sales'[Period] = PreviousYear,
ALL('Calendar')
)

 

It works.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi, @SGBaringa 

Based on your information, I I reproduce your situation.

I found no problem with your DAX. When I create a one-to-many relationship, when I use your DAX expression, there are no values in the table view.

vyohuamsft_0-1723170318593.png

vyohuamsft_1-1723170338750.png

 

You need to untie the two so that the table view shows the values of the previous year, and when there is no previous year, the table view will still appear empty.

vyohuamsft_2-1723170452370.png

vyohuamsft_3-1723170498848.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

rajendraongole1
Super User
Super User

Hi @SGBaringa - you are getting that issue because of the filter context applied on slicer calender entity.

 

can you check the below formaule:

PreviousYearRevenue =
VAR SelectedYear = SELECTEDVALUE('Calendar'[Year])
VAR PreviousYear = SelectedYear - 1
RETURN
CALCULATE(
SUM('Sales'[Revenue]),
'Sales'[Period] = PreviousYear,
ALL('Calendar')
)

 

It works.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





This worked! Thank you so much @rajendraongole1 !

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors