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

Running Total for non-calendar year line chart

Hi,

 

I'm struggling creating a line chart showing running total over non-calendar (Gas) years, that would correctly perserve the order of the months.

 

Desired features:

  • A Gas year is 1 Oct - 30 Sept. Hence the line chart should be showing Oct first and Sept last. This means that Oct 2020 and January 2021 are for the sake of this chart both 2021 (as shown in the data below), and cumulative total should start on Oct 1st.
  • The chart should take user filtes into account, hence it needs to be calculated using a meassure applying existing filters

Data (note the Category column for filter testing purposes)

gy1.PNG

 

 

 

 

 

 

 

 

 

For a calendar year, the solution is relatively simple, using TOTALYTD function

Q_YTD = TOTALYTD(Sum('Table'[Quantity]), 'Table'[Date].[Date], ALLSELECTED('Table'))
 
image.pngAxis: Date.Month
Legend: Date.Year
Values: Q_YTD
 

 

 

 

 

 

 

 

 

So the desired line chart would have Oct - Sept months on the x-axis, calculating running total across those months using GasYear (instead of Calendar year). The quantities should stay allocated to months as they are. Keep in mind that running total is starting in October (not Jan).

 

I was able to calculate the numbers correctly (using last argument into TOTALYTD function as "30/09"), but I'm really struggling to then plot the results on a line chart with the months in desired order (Oct - Sept) and correct Gas Years in legend.

 

Gas years for illustration

image.png

 

Attaching PBIX

 

Any help greatly appreciated,

Stefan

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous  ,

 

If you want to calculate YTD according to your fiscal year, I suggest you use the following dax code:
 

 

Q_YTD =

CALCULATE (

    SUM ( 'Table'[Quantity] ),

    FILTER (

        ALL ( 'Table' ),

        'Table'[Date] <= MAX ( 'Table'[Date] )

            && 'Table'[GasYear] = MAX ( 'Table'[GasYear] )

    )

)

 

 

You can use a calendar table to sort the months on the X-axis by your fiscal year. Please follow the steps below:

Create a calendar table:

 

 

Date = CALENDAR(DATE(2020,1,1),DATE(2021,12,31))

 

 

Create month and fiscal month columns in the calendar table:

 

 

Month = FORMAT('Date'[Date].[Month],"MMM")

 

 

 

FYMonthNum =

VAR FYStartMonth = 10

RETURN

    IF (

        MONTH ( 'Date'[Date] ) >= FYStartMonth,

        MONTH ( 'Date'[Date] ) - ( FYStartMonth - 1 ),

        12 + MONTH ( 'Date'[Date] ) - ( FYStartMonth - 1 )

    )

 

 

Sort the month column by FYMonthNum column:

 

Untitled picture.png

 

Associate the calendar table with the original table:

 

Untitled picture1.png

 

Use Month as Axis :

 

 

Untitled picture2.png

 

Please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EW803EfvBQ1Muao92mfHsfABCxwe68n0sQSPeEDNx0cD6A?e=cp1cOE

 

Best Regards,

Dedmon Dai

View solution in original post

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous  ,

 

If you want to calculate YTD according to your fiscal year, I suggest you use the following dax code:
 

 

Q_YTD =

CALCULATE (

    SUM ( 'Table'[Quantity] ),

    FILTER (

        ALL ( 'Table' ),

        'Table'[Date] <= MAX ( 'Table'[Date] )

            && 'Table'[GasYear] = MAX ( 'Table'[GasYear] )

    )

)

 

 

You can use a calendar table to sort the months on the X-axis by your fiscal year. Please follow the steps below:

Create a calendar table:

 

 

Date = CALENDAR(DATE(2020,1,1),DATE(2021,12,31))

 

 

Create month and fiscal month columns in the calendar table:

 

 

Month = FORMAT('Date'[Date].[Month],"MMM")

 

 

 

FYMonthNum =

VAR FYStartMonth = 10

RETURN

    IF (

        MONTH ( 'Date'[Date] ) >= FYStartMonth,

        MONTH ( 'Date'[Date] ) - ( FYStartMonth - 1 ),

        12 + MONTH ( 'Date'[Date] ) - ( FYStartMonth - 1 )

    )

 

 

Sort the month column by FYMonthNum column:

 

Untitled picture.png

 

Associate the calendar table with the original table:

 

Untitled picture1.png

 

Use Month as Axis :

 

 

Untitled picture2.png

 

Please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EW803EfvBQ1Muao92mfHsfABCxwe68n0sQSPeEDNx0cD6A?e=cp1cOE

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

HI @v-deddai1-msft ,

 

This is StefanZ - your solution works, thank you so much for you effert. 

 

And apologies for not marking your answer as as correct, I'm unable to log in with my original accout, I don't know why. The Power Bi Community sign in protocols are really complicated. 

 

Kind Regards

Stefan

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!

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.