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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Marcus2
Helper I
Helper I

Running Total (prior 3 fiscal years)

Hi,  how can I get 3 prior years from the FY selected.  My goal is to select a single year (2024 in this example) and view data three years prior (with final aggregation month selected in a second slicer).   Is there a DAX for this?

 

FY

Month

Value
2022Oct5
2022Nov5
2022Dec5
2022Jan5
2022Feb5
2022Mar5
2022Apr5
2022May5
2022Jun5
2022Jul5
2022Aug5
2022Sep5
2023Oct5
2023Nov5
2023Dec5
2023Jan5
2023Feb5
2023Mar5
2023Apr5
2023May5
2023Jun5
2023Jul5
2023Aug5
2023Sep5

2024

Oct5
2024Nov5
2024Dec5
2024Jan5
2024Feb 
2024Mar 
2024Apr 
2024May 
2024Jun 
2024Jul 
2024Aug 
2024Sep 

 

Desired table result with FY2024 and Nov slicer selections:

 

FYMonthFYTD
2022Oct5
2022Nov10
2022Dec15
2022Jan20
2022Feb25
2022Mar30
2022Apr35
2022May40
2022Jun45
2022Jul50
2022Aug55
2022Sep60
2023Oct5
2023Nov10
2023Dec15
2023Jan20
2023Feb25
2023Mar30
2023Apr35
2023May40
2023Jun45
2023Jul50
2023Aug55
2023Sep60
2024Oct5
2024Nov10
2024Dec 
2024Jan 
2024Feb 
2024Mar 
2024Apr 
2024May 
2024Jun 
2024Jul 
2024Aug 
2024Sep 

 

1 ACCEPTED SOLUTION
sanalytics
Super User
Super User

@Marcus2 
Dont understand the  your exact output what you are looking for. 
I have assumed 3 scenario output. Below are the details

1) Lets you are looking for total aggegate value for 3 year's prior and same month.. For example, if you select 2025 in year slicer and sep in Month slicer. You want to sum up prior 3 years (2022,2023,2024) sep's value then below code will work

 

 

Total Aggregate Value = 
VAR _Selection = MAX( Data[FY] )
VAR _1stYr = _Selection - 1
VAR _2ndYr = _Selection - 2
VAR _3rdYr = _Selection - 3
VAR _tbl = 
UNION(
ROW("@yr",_1stYr),
ROW( "@yr",_2ndYr),
ROW("@yr",_3rdYr)
 )
VAR _vtable = 
TREATAS(
    _tbl,Data[FY]
)
VAR _Result = 
CALCULATE(
    SUM(Data[Value] ),
    _vtable
)
RETURN
_Result

 

 

 

2) If you want to show,, total value from 2022 sep to 2024 sep. The below is code

 

 

Full Data Value = 
SUMX(
VALUES( Data[Index] ),
VAR _endIndex = MAX( Data[Index] ) - 12
VAR _StarIndex = MAX( Data[Index] ) - 36
VAR _tbl = 
FILTER(
ALL( Data ),
Data[Index] <= _endIndex &&
Data[Index] >= _StarIndex
)
VAR _check = 
COUNTROWS( _tbl )
VAR _Result = 
SUMX(
    _tbl,[Value]
)

RETURN
_Result
)

 

 

 

3) if you want to only show only 3 years (2022 sep,2023 sep,2024 sep) data in a table visual..then check the below pbix file for steps. Page name -> Showdata.

 

Below screenshot

sanalytics_0-1738322490196.png

Attached pbis file for your reference.

 

Hope it helps

 

Regards

sanalytics

View solution in original post

3 REPLIES 3
Poojara_D12
Super User
Super User

Hi @Marcus2 

I think you need to:

  1. Capture the selected FY from a slicer.
  2. Determine the three prior years dynamically.
  3. Filter the data to include only the selected month up to the chosen month in all relevant years.

Please use this dax;

Filtered Value =
VAR SelectedFY = SELECTEDVALUE('FY_Table'[FY]) -- Captures the selected fiscal year
VAR SelectedMonth = SELECTEDVALUE('FY_Table'[Month]) -- Captures the selected month
VAR StartFY = SelectedFY - 3  -- Compute three years prior

RETURN
CALCULATE(
    SUM('FY_Table'[Value]), -- Aggregating the values
    'FY_Table'[FY] >= StartFY && 'FY_Table'[FY] < SelectedFY, -- Includes three prior years
    'FY_Table'[Month] <= SelectedMonth -- Filters months up to the selected one
)

 

 

  • If you want to display this filtered data in a table visual, create a calculated column instead of a measure.
  • If the fiscal year starts in a month other than January (e.g., July), adjust the FY logic accordingly.

 

 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
sanalytics
Super User
Super User

@Marcus2 
Dont understand the  your exact output what you are looking for. 
I have assumed 3 scenario output. Below are the details

1) Lets you are looking for total aggegate value for 3 year's prior and same month.. For example, if you select 2025 in year slicer and sep in Month slicer. You want to sum up prior 3 years (2022,2023,2024) sep's value then below code will work

 

 

Total Aggregate Value = 
VAR _Selection = MAX( Data[FY] )
VAR _1stYr = _Selection - 1
VAR _2ndYr = _Selection - 2
VAR _3rdYr = _Selection - 3
VAR _tbl = 
UNION(
ROW("@yr",_1stYr),
ROW( "@yr",_2ndYr),
ROW("@yr",_3rdYr)
 )
VAR _vtable = 
TREATAS(
    _tbl,Data[FY]
)
VAR _Result = 
CALCULATE(
    SUM(Data[Value] ),
    _vtable
)
RETURN
_Result

 

 

 

2) If you want to show,, total value from 2022 sep to 2024 sep. The below is code

 

 

Full Data Value = 
SUMX(
VALUES( Data[Index] ),
VAR _endIndex = MAX( Data[Index] ) - 12
VAR _StarIndex = MAX( Data[Index] ) - 36
VAR _tbl = 
FILTER(
ALL( Data ),
Data[Index] <= _endIndex &&
Data[Index] >= _StarIndex
)
VAR _check = 
COUNTROWS( _tbl )
VAR _Result = 
SUMX(
    _tbl,[Value]
)

RETURN
_Result
)

 

 

 

3) if you want to only show only 3 years (2022 sep,2023 sep,2024 sep) data in a table visual..then check the below pbix file for steps. Page name -> Showdata.

 

Below screenshot

sanalytics_0-1738322490196.png

Attached pbis file for your reference.

 

Hope it helps

 

Regards

sanalytics

bhanu_gautam
Super User
Super User

@Marcus2 , First create a measure to capture selected month and year

SelectedFY =
SELECTEDVALUE('Table'[FY])

 

SelectedMonth =
SELECTEDVALUE('Table'[Month])

 

Now create a measure to calculate on the basis of this

Sum3YearsPrior =
VAR CurrentFY = [SelectedFY]
VAR CurrentMonth = [SelectedMonth]
VAR PriorFY1 = CurrentFY - 1
VAR PriorFY2 = CurrentFY - 2
VAR PriorFY3 = CurrentFY - 3
VAR EndDate = DATE(CurrentFY, MONTH(DATEVALUE("1 " & CurrentMonth & " " & CurrentFY)), DAY(DATEVALUE("1 " & CurrentMonth & " " & CurrentFY)))
VAR StartDate = DATE(PriorFY3, MONTH(DATEVALUE("1 " & CurrentMonth & " " & PriorFY3)), DAY(DATEVALUE("1 " & CurrentMonth & " " & PriorFY3)))
RETURN
CALCULATE(
SUM('Table'[Value]),
DATESBETWEEN('Table'[Date], StartDate, EndDate)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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