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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hprose
Helper I
Helper I

Calculate Fiscal Average with conditions

Hi, I have data in the below format(first 2 columns). The fiscal year end month is June. I want to calculate the fiscal average for FY21 & FY22 as shown in the third column. Can someone help? I tried using TOTALYTD and AVERAGE but it doesnt seem to be working. Besides, I need to apply 2 filters and TOTALYTD doesn't allow it. For example, Column A = "X" && Column B = "Y" in the calculation. Thanks! 

Note that I do have a calendar table.

 

Also - if the fiscal year hasn't ended, it needs to be YTD average. My goal is to add an average line for each fiscal year along with the actual values.

 

MonthYearValueFiscal Average
Jul-20200750
Aug-20300750
Sep-20400750
Oct-20500750
Nov-20600750
Dec-20700750
Jan-21800750
Feb-21900750
Mar-211000750
Apr-211100750
May-211200750
Jun-211300750
Jul-2114001950
Aug-2115001950
Sep-2116001950
Oct-2117001950
Nov-2118001950
Dec-2119001950
Jan-2220001950
Feb-2221001950
Mar-2222001950
Apr-2223001950
May-2224001950
Jun-2225001950
July-2226002800
Aug-2230002800

 

1 ACCEPTED SOLUTION
hprose
Helper I
Helper I

I did end up solving this. It's not the most elegant solution,  but it gets me the result I want. Hope this helps someone. 

 

Formulas: 

 

2022Rolling = 
CALCULATE([Value$],DATESYTD(Calendar[Calendar_Date],"06/30"),Calendar[Fiscal_Year]=2022)
--My calendar only has months, that's why I'm using countrows here.
Months2022 =
IF(SELECTEDVALUE(CALENDAR[Fiscal Year]) = 2021, Blank(),CALCULATE(COUNROWS(Calendar),Calendar[Fiscal Year] = 2022,ALL(Calendar)))
2022YTD_constant = 
IF(SELECTEDVALUE(CALENDAR[Fiscal Year]) = 2021, Blank(),CALCULATE([2022Rolling],ALL(Calendar)))
FiscalAverage2022 = CALCULATE(2022YTD_constant/Months2022)

Do the same for another fiscal year if needed. This will give you dynamic average lines similar to the chart below.

 

image1.png

View solution in original post

5 REPLIES 5
hprose
Helper I
Helper I

I did end up solving this. It's not the most elegant solution,  but it gets me the result I want. Hope this helps someone. 

 

Formulas: 

 

2022Rolling = 
CALCULATE([Value$],DATESYTD(Calendar[Calendar_Date],"06/30"),Calendar[Fiscal_Year]=2022)
--My calendar only has months, that's why I'm using countrows here.
Months2022 =
IF(SELECTEDVALUE(CALENDAR[Fiscal Year]) = 2021, Blank(),CALCULATE(COUNROWS(Calendar),Calendar[Fiscal Year] = 2022,ALL(Calendar)))
2022YTD_constant = 
IF(SELECTEDVALUE(CALENDAR[Fiscal Year]) = 2021, Blank(),CALCULATE([2022Rolling],ALL(Calendar)))
FiscalAverage2022 = CALCULATE(2022YTD_constant/Months2022)

Do the same for another fiscal year if needed. This will give you dynamic average lines similar to the chart below.

 

image1.png

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
hprose
Helper I
Helper I

Hi @v-rzhou-msft ,

 

Thank you very much for the detailed response. Apologies, I should have provided some use cases for more context. I'm looking to calculate dynamic averages based on filters selected, so unfortunately, the calculated column did not work. However, I did end up solving this. Thanks for your help!

@Ashish_Mathur Thank you for response. I'm looking to have the average be visible alongside all the months. I should have included more use cases. I did end up solving this. Appreciate your help!

v-rzhou-msft
Community Support
Community Support

Hi @hprose ,

 

Here I suggest you to create a Calendar table with Fiscal Year and then create calculated columns.

Calendar = 
VAR _BASIC =
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2020, 01, 01 ), DATE ( 2022, 12, 31 ) ),
        "Year", YEAR ( [Date] ),
        "Month", MONTH ( [Date] ),
        "MonthName", FORMAT ( [Date], "MMMM" ),
        "MonthYearNum",
            YEAR ( [Date] ) * 100
                + MONTH ( [Date] ),
        "MonthYear", FORMAT ( [Date], "MMM-YY" )
    )
VAR _FISCAL =
    ADDCOLUMNS ( _BASIC, "FiscalYear", IF ( [Month] > 6, [Year] + 1, [Year] ) )
RETURN
    _FISCAL

Calculated columns:

Fiscal Year = 
CALCULATE(MAX('Calendar'[FiscalYear]))
Fiscal Average = AVERAGEX(FILTER('Table',[Fiscal Year] = EARLIER('Table'[Fiscal Year])),[Value])

Result is as below.

RicoZhou_0-1667548047785.png

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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