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
Anonymous
Not applicable

Getting previous and current year data

Hi all,

I am trying to achieve the following table where I want to show the Rate for the current and past year

qnnn8_0-1742881660072.png

and my data is like the following

qnnn8_2-1742881840664.png

I have a slicer for users to select the year they wish to see and the table should show the rates for that year + the previous year 

(E.g. if 2025 is selected, rates for 2025 and 2024 should be shown in the table)

 

I have the measures 

Selected Year = SELECTEDVALUE(SPI[Year])
Incident Rate Selected Year = CALCULATE(SUM(SPI[Incidents Rate]), FILTER(SPI,'SPI'[Year] = [Selected Year])) which works 
and 
Incident Rate Previous Year = CALCULATE(SUM(SPI[Incidents Rate]), FILTER(SPI,'SPI'[Year] = SELECTEDVALUE(SPI[Year])-1))
but this measure returns blank
 
Any help is much appreciated!

 

 

 

2 ACCEPTED SOLUTIONS
mdaatifraza5556
Super User
Super User

Hi @Anonymous 

Can you please try the below DAX?

 


For the prev



VAR Selected_Year = SELECTEDVALUE(SPI[Year])
RETURN
CALCULATE(
SUM(SPI[Incidents Rate]), 'SPI'[Year] = Selected_Year-1)

If this answers your questions, kindly accept it as a solution.

View solution in original post

danextian
Super User
Super User

Hi @Anonymous 

 

If you're meaning to just get the previous year's rate based on the current slicer selection, you can try this:

PY Rate =
CALCULATE (
    SUM ( SampleData[Incidents Rate] ),
    FILTER (
        ALL ( SampleData[Year] ),
        SampleData[Year]
            = MAX ( SampleData[Year] ) - 1
    )
)

If there is no year selected, it will return the max year - 1's value.

 

If the goal is to make the column name dynamic as well, a disconnected table will be needed to store all possible column names—such as Alert, Number of Incidents, and Targets—along with their corresponding sort values. Additionally, a measure will be required to determine whether to return a value based on the selected year and the values in the disconnected table. This is not a straightforward task.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
danextian
Super User
Super User

Hi @Anonymous 

 

If you're meaning to just get the previous year's rate based on the current slicer selection, you can try this:

PY Rate =
CALCULATE (
    SUM ( SampleData[Incidents Rate] ),
    FILTER (
        ALL ( SampleData[Year] ),
        SampleData[Year]
            = MAX ( SampleData[Year] ) - 1
    )
)

If there is no year selected, it will return the max year - 1's value.

 

If the goal is to make the column name dynamic as well, a disconnected table will be needed to store all possible column names—such as Alert, Number of Incidents, and Targets—along with their corresponding sort values. Additionally, a measure will be required to determine whether to return a value based on the selected year and the values in the disconnected table. This is not a straightforward task.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
mdaatifraza5556
Super User
Super User

Hi @Anonymous 

Can you please try the below DAX?

 


For the prev



VAR Selected_Year = SELECTEDVALUE(SPI[Year])
RETURN
CALCULATE(
SUM(SPI[Incidents Rate]), 'SPI'[Year] = Selected_Year-1)

If this answers your questions, kindly accept it as a solution.

pankajnamekar25
Super User
Super User

Please try this Incident Rate Previous Year =
VAR SelectedYr = [Selected Year] 
RETURN
CALCULATE(
SUM(SPI[Incidents Rate]),
FILTER(SPI, SPI[Year] = SelectedYr - 1)
)

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 Solution Authors
Top Kudoed Authors