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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Marcus2
Frequent Visitor

FY running total for prior 3 fiscal years (table visual)

Hi,  how can I get 3 prior years from the FY and month selected.  I've created a calendar table and used DAX, but current DAX doesn't stop aggregating at my selected end month (I also have to multiselect the years... goal is to select final year).

 

Here's my initial data:

 DateFY

Month

Value
10/31/2021      2022    Oct    5    

11/30/2021

2022Nov5
12/31/20212022Dec5
1/31/20222022Jan5
2/28/20222022Feb5
3/31/20222022Mar5
4/30/20222022Apr5
5/31/20222022May5
6/30/20222022Jun5
7/31/20222022Jul5
8/31/20222022Aug5

9/30/2022

2022Sep5
10/31/20222023Oct5

11/30/2022

2023Nov5
12/31/20222023Dec5
1/31/20232023Jan5
2/28/20232023Feb5
3/31/20232023Mar5
4/30/20232023Apr5
5/31/20232023May5
6/30/20232023Jun5
7/31/20232023Jul5
8/31/20232023Aug5

9/30/2023

2023Sep5
10/31/2023

2024

Oct5

11/30/2023

2024Nov5
12/31/20232024Dec5
1/31/20242024Jan5
2/29/20242024Feb 
3/31/20242024Mar 
4/30/20242024Apr 
5/31/20242024May 
6/30/20242024Jun 
7/31/20242024Jul 
8/31/20242024Aug 

9/30/2024

2024Sep 

 

Desired result with FY2024 and Nov slicer selections:

 

 DateFYMonthFYTD
10/31/2021      2022    Oct    5    

11/30/2021

2022Nov10
12/31/20212022Dec15
1/31/20222022Jan20
2/28/20222022Feb25
3/31/20222022Mar30
4/30/20222022Apr35
5/31/20222022May40
6/30/20222022Jun45
7/31/20222022Jul50
8/31/20222022Aug55

9/30/2022

2022Sep60
10/31/20222023Oct5

11/30/2022

2023Nov10
12/31/20222023Dec15
1/31/20232023Jan20
2/28/20232023Feb25
3/31/20232023Mar30
4/30/20232023Apr35
5/31/20232023May40
6/30/20232023Jun45
7/31/20232023Jul50
8/31/20232023Aug55

9/30/2023

2023Sep60
10/31/20232024Oct5

11/30/2023

2024Nov10
12/31/20232024Dec 
1/31/20242024Jan 
2/29/20242024Feb 
3/31/20242024Mar 
4/30/20242024Apr 
5/31/20242024May 
6/30/20242024Jun 
7/31/20242024Jul 
8/31/20242024Aug 

9/30/2024

2024Sep 
11 REPLIES 11
v-nuoc-msft
Community Support
Community Support

Hi @Marcus2 

 

Thank you very much DataNinja777 or your prompt reply.

 

For your question, here is the method I provided:

 

Create a calendar table.

 

Calendar = 
ADDCOLUMNS (
    CALENDAR (MIN('Table'[Date]), MAX('Table'[Date])),
    "FY", YEAR([Date]) + IF(MONTH([Date]) > 9, 1, 0),
    "Month", MONTH([Date])
)

 

Create a measure.

 

FYTD Value = 
VAR SelectedFY = SELECTEDVALUE('Calendar'[FY])
VAR SelectedMonth = SELECTEDVALUE('Calendar'[Month])
VAR PriorYearsFYTD = 
    CALCULATE (
        SUM('Table'[Value]),
        FILTER(
            'Calendar',
            'Calendar'[FY] IN {SelectedFY - 1, SelectedFY - 2, SelectedFY - 3} 
        )
    )
RETURN
    SUMX(
        FILTER(
            ALL('Table'),
            'Table'[FY] = MAX('Table'[FY]) 
            &&
            'Table'[Date] <= MAX('Table'[Date])
        ),
        PriorYearsFYTD
    )

 

Here is the result.

vnuocmsft_0-1738574977978.png

 

Regards,

Nono Chen

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

 

Thanks @v-nuoc-msft, do you have a pbix file compatible with PowerBI Version 2.116?  I tried a work around opening your file in PowerBI Service but slicers wouldn't control dates.  🙂 

Hi @Marcus2 

 

I modified the code, you can try it again:

 

Calendar = 
ADDCOLUMNS (
    SELECTCOLUMNS('Table', "Date", 'Table'[Date]),
    "FY", YEAR([Date]) + IF(MONTH([Date]) > 9, 1, 0),
    "Month", MONTH([Date])
)

 

FYTD Value = 
VAR SelectedFY = SELECTEDVALUE('Calendar'[FY])
VAR SelectedDate = SELECTEDVALUE('Calendar'[Date])
VAR PriorYearsFYTD = 
    CALCULATE (
        SUM('Table'[Value]),
        FILTER(
            'Table',
            YEAR('Table'[Date]) IN {SelectedFY - 1, SelectedFY - 2, SelectedFY - 3} 
            &&
            'Table'[Date] <= SelectedDate 
        )
    )
RETURN
    SUMX(
        FILTER(
            ALL('Table'),
            'Table'[FY] = MAX('Table'[FY])
            &&
            'Table'[Date] <= MAX('Table'[Date])
        ),
        PriorYearsFYTD
    )

 

vnuocmsft_0-1738810678051.png

 

vnuocmsft_1-1738810722964.png

 

Regards,

Nono Chen

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

 

 

Great thanks @v-nuoc-msft , are you able to see slicer actions between months 9 and 1?  Seems to function great at 10, 11, and 12.  Also, I noticed if I replace 5s with random numbers for my source data... the FYTD running total doesn't increase perfectly.  Are you able to swap the 5s with radom numbers?

Hi @Marcus2 

 

Try this:

 

FYTD Value = 
VAR SelectedFY = SELECTEDVALUE('Calendar'[FY])
VAR SelectedMonth = SELECTEDVALUE('Calendar'[Month])
VAR PriorYearsFYTD = 
    CALCULATE (
        SUM('Table'[Value]),
        FILTER(
            'Table',
            YEAR('Table'[Date]) IN {SelectedFY - 1, SelectedFY - 2, SelectedFY - 3} 
            &&
            'Table'[Date] <= DATE(SelectedFY - 1, SelectedMonth, 31) 
        )
    )
RETURN
    SUMX(
        FILTER(
            ALL('Table'),
            'Table'[FY] = MAX('Table'[FY])
            &&
            'Table'[Date] <= MAX('Table'[Date])
            
        ),
        PriorYearsFYTD
    )

 

vnuocmsft_5-1738893039282.png

 

If you need to replace "5" with a random number, you can select your data table in the Power Query Editor. Add a custom column and use the following formula to generate a random number:

 

= if [Value] = 5 then Number.RoundDown(Number.RandomBetween(1, 100)) else [Value]

 

vnuocmsft_1-1738891680500.png

 

And make sure the data type is a numeric type.

vnuocmsft_2-1738891733096.png

 

You can get:

 

vnuocmsft_3-1738891833652.png

 

vnuocmsft_4-1738891869609.png

 

Regards,

Nono Chen

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

 

Thanks, slicer works with this DAX @v-nuoc-msft ,  Please see your random number screenshot below... the running total is not increasing.   Thanks again.

 

Marcus2_0-1738935430643.png

 

Hi @Marcus2 

 

Try this:

 

FYTD Value = 
VAR SelectedFY = SELECTEDVALUE('Calendar'[FY])
VAR SelectedMonth = SELECTEDVALUE('Calendar'[Month])
VAR SelectedDate = DATE(SelectedFY - 1, SelectedMonth, 31)
VAR PriorYearsFYTD = 
    CALCULATE (
        SUM('Table'[Custom]),
        FILTER(
            ALL('Table'),
            'Table'[FY] = MAX('Table'[FY])
            &&
            'Table'[Date] <= MAX('Table'[Date])
            &&
            YEAR('Table'[Date]) IN {SelectedFY - 1, SelectedFY - 2, SelectedFY - 3} 
            &&
            'Table'[Date] <= SelectedDate
        )
    )
RETURN
    IF(
        SELECTEDVALUE('Table'[Date]) <= SelectedDate,
        PriorYearsFYTD,
        BLANK()
    )

 

Here is the result.

 

vnuocmsft_0-1739176461390.png

 

Regards,

Nono Chen

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

 

 

 

techies
Regular Visitor

please check this

YTD_Running_Total =
VAR SelectedFY = SELECTEDVALUE('DATE'[Year])
VAR SelectedMonth = SELECTEDVALUE('DATE'[Month])
 
VAR MaxDate =
    MAXX(
        FILTER(
            ALL('DATE'),
            'DATE'[Year] = SelectedFY &&
            'DATE'[Month] = SelectedMonth
        ),
        'DATE'[Date]
    )
VAR StartDate = DATE(YEAR(MaxDate) - 2, 1, 1)

 
RETURN
CALCULATE(
    SUMX(
        FILTER(
            ALL('DATE'),
            'DATE'[Date] >= StartDate && 'DATE'[Date] <= MaxDate
        ),
        value
    )
)

Hi, I'm trying your DAX but I think something is missing in front of "value" near the last line.  I'm getting a syntax error message.

Marcus2
Frequent Visitor

@DataNinja777 thanks,  I'm still getting the same results as before.  Could it be my coloumn data types?  With your DAX provided I get the following:

 

(FY2024 and Dec) slicer selections: (just one year)

FYMonthFYTD
2024Dec15

 

Just FY2024 slicer selection: (just one year; it repeats the last month of available FY data)

FYMonthFYTD

2024

Oct5
2024Nov10
2024Dec15
2024Jan20
2024Feb20
2024Mar20
2024Apr20
2024May20
2024Jun20
2024Jul20
2024Aug20
2024Sep20

 

Current coloumn data types:

Calendar [Date] = Date/time

Calendar [FY] = Whole number

Calendar [FYMonthNumber] = Whole number

Calendar [MonthName] = Text

Calendar [MonthNumber] = Whole number

 

DataTable [Date] = Date/time

DataTable [FY] = Whole number

DataTable [FYMonthNumber] = Whole number

DataTable [MonthName] = Text

DataTable [MonthNumber] = Whole number

DataNinja777
Super User
Super User

Hi @Marcus2 ,

 

The most straightforward and standard way to calculate the Fiscal Year-To-Date (FYTD) running total for the prior three years while ensuring the accumulation stops at the selected month is by using TOTALYTD. This function automatically resets the total at the beginning of each fiscal year, making it the best choice for this scenario.

FYTD Running Total =
VAR SelectedFY = SELECTEDVALUE( 'Calendar'[FY] )
VAR SelectedMonth = SELECTEDVALUE( 'Calendar'[Month] )

RETURN
CALCULATE(
    TOTALYTD(
        SUM( 'Table'[Value] ),
        'Calendar'[Date],
        "9/30"  -- Adjust this if your fiscal year ends in a different month
    ),
    'Calendar'[FY] >= SelectedFY - 3 && 'Calendar'[FY] <= SelectedFY,
    'Calendar'[Month] <= SelectedMonth
)

This formula ensures that the FYTD calculation correctly accumulates within each fiscal year while stopping at the selected month. The "9/30" parameter specifies that the fiscal year ends in September, so update it if your fiscal year follows a different cycle. This is the most standard approach and should work efficiently with your Power BI model.

 

Best regards,

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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