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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Total Calculations for Year and dynamic Year column

I have a date slicer and trying to achieve the below 

 

1. Total calculations for the previous 3 years. Fiscal year ends on 04/30. If the date selected is 05/01/2018 to 04/30/2019, Need to calculate the Year totals for 2015 , 2016 & 2017 . 

I used CALCULATE([Current Year Invoice],PREVIOUSYEAR('Calendar'[Date],"04/30")) for the last year. How to restrict to fiscal year ending 04/30 for previous years. 
2. How to dynamically change the column header based on the date selected . if  2019 year is selected, report should have these columns 
 
2016 Total2017 Total2018 Total
   
 
if 2018 year is selected.  Column header need to be dynamic based on date selection. 
2015 Total2016 Total2017 Total
   
 
 

 

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario.

Table:

e1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

New Table(a calculated table):

New Table = 
ADDCOLUMNS(
    DISTINCT('Calendar'[FY]),
    "Num",
    RANKX(
        DISTINCT('Calendar'[FY]),
        [FY],,ASC
    )
)

 

There is a relationship between 'Calendar' and 'Table'.

 

You may create a calculated column and two measures as below.

Calculated column:
FY = 
var _date = 'Calendar'[Date]
var _year = YEAR(_date)
var _month = MONTH(_date)
return
IF(
    _month<=4,
    (_year-1)&"-"&_year,
    _year&"-"&(_year+1)
)

FY Total = 
CALCULATE(
    SUM('Table'[Invoice]),
    DATESYTD('Calendar'[Date],"04-30")
)

Visual control = 
var _selectedfy = SELECTEDVALUE('New Table'[FY])
var _selectednum = SELECTEDVALUE('New Table'[Num])
var _fy = SELECTEDVALUE('Calendar'[FY])
var _num = LOOKUPVALUE('New Table'[Num],'New Table'[FY],_fy)
return
IF(
    ISFILTERED('New Table'[FY]),
    IF(
        _selectednum-_num<=3&&
        _selectednum-_num>0,
        1,0
    ),
    1
)

 

Finally you need to put the measure 'Visual control' in the corresponding visual level filter to display the result.

e2.png

e3.png

 

Best Regards

Allan

 

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

 

Anonymous
Not applicable

Hi @v-alq-msft 

 

Thanks for taking the time to respond. That didn't help me on the column header question. 

 

Attaching a link to the test model. https://drive.google.com/open?id=1yfKw2A5G4rqMtQoy7cdBbrqFfDyGhxju

 

I wanted to know if it is possible to dynamically get the column headers. 

If the selected slicer is for the fY 2020, I will need to show the prior 2 year totals.   

FY 2018  FY 2019  FY2020  . If the slicer is for FY2019,  the column name should be  FY2017 FY2018 FY2019. 

 

 

In the below, instaed of Last year, is it possible to derive column name as 2019? 

 

cap1.JPG

AllisonKennedy
Super User
Super User

@Anonymous  Try using DATEADD instead of PREVIOUSYEAR. This allows you to specify which period (YEAR, MONTH or DAY) and how many (so -1 for previous year, -2 for 2 years ago, -3 for 3 years ago).

 

Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 

 

If you found this post helpful, please give Kudos.

I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 

https://sites.google.com/site/allisonkennedycv


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Thanks @AllisonKennedy . 

 

But, I thought this will take the calendar year rather than the fiscal year that i wanted.Let me test it out. 

Also, the second part of the question is what i was more keen to figure out if it is possible to dynamically change the column header according to the year derived. 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors
Top Kudoed Authors