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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mfp32
New Member

Calculate Average of a Measure by Year to Date

Hi!

 

Very new to PBI! Looking for guidance / help how to do the following logic.

 

I have a table as shown below. I need to add a new measure called YTD ATT that averages Year-to-Date values of the measure called MONTHLY ATT.

 

For example:

January 2019, the YTD Att would be 0.1448

In February, it should be 0.1449 (average of January and February MONTHLY ATT)

In March, it should be 0.1591 (average of January to March MONTHLY ATT)

In December, it would have been the average of all MONTHLY ATT values of 2019.

Then for January 2020, it would repeat again.

 

mfp32_0-1665054389778.png

 

 

 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @mfp32 ,

 

Since I don't know what your raw data is. I made sample data on my own.

vstephenmsft_0-1665473685284.png

You could see the column of month numbers in my sample data. You need to add a column of month numbers to your table too. You can get the month number using the MONTH function. Or replace the text month with a numeric month with the SWITCH function.

 

I also created a metric to return to Monthly ATT.

vstephenmsft_1-1665473836166.png

Then the YTD ATT could be created like

YTD ATT = AVERAGEX(FILTER(ALLSELECTED('Table'),[Year]=MAX('Table'[Year])&&[Month Number]<=MAX('Table'[Month Number])),[Monthly ATT])

vstephenmsft_3-1665473940141.png

If you want to round down, add ROUNDDOWN function.

YTD ATT = ROUNDDOWN(AVERAGEX(FILTER(ALLSELECTED('Table'),[Year]=MAX('Table'[Year])&&[Month Number]<=MAX('Table'[Month Number])),[Monthly ATT]),4)

vstephenmsft_4-1665474010838.png

 

 

 

 

Best Regards,

Stephen Tao

 

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

 

View solution in original post

11 REPLIES 11
agage5
Regular Visitor

Hello, I tried to follow your logic but I am getting an error.  The MAX function only accepts a column reference as an argument.

 

In my SAP scrap actuals table I have quantity actuals for FY23/FY24 periods 1-12 in FY23, and 1-6 in FY24.  I am trying to get the average of all of those months for quantity.  So it would be YTD period 6 would be the history of 18 months for quantity - one number for YTD.  I added the month name.  My month number = period for my table.  I added a quantity measure which is this 

Quantity measure = CALCULATE(sum(SAP_Scrap_Actuals[Quantity])).  FY = Year

 

DAX below getting error.

YTD ATT = AVERAGEX(FILTER(ALLSELECTED(SAP_Scrap_Actuals),SAP_Scrap_Actuals[FY]=max(SAP_Scrap_Actuals[FY]&&SAP_Scrap_Actuals[Period]=max(SAP_Scrap_Actuals[Period])),[Quantity measure]))
Anonymous
Not applicable

Hi @mfp32 ,

 

Since I don't know what your raw data is. I made sample data on my own.

vstephenmsft_0-1665473685284.png

You could see the column of month numbers in my sample data. You need to add a column of month numbers to your table too. You can get the month number using the MONTH function. Or replace the text month with a numeric month with the SWITCH function.

 

I also created a metric to return to Monthly ATT.

vstephenmsft_1-1665473836166.png

Then the YTD ATT could be created like

YTD ATT = AVERAGEX(FILTER(ALLSELECTED('Table'),[Year]=MAX('Table'[Year])&&[Month Number]<=MAX('Table'[Month Number])),[Monthly ATT])

vstephenmsft_3-1665473940141.png

If you want to round down, add ROUNDDOWN function.

YTD ATT = ROUNDDOWN(AVERAGEX(FILTER(ALLSELECTED('Table'),[Year]=MAX('Table'[Year])&&[Month Number]<=MAX('Table'[Month Number])),[Monthly ATT]),4)

vstephenmsft_4-1665474010838.png

 

 

 

 

Best Regards,

Stephen Tao

 

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

 

I have a simialr issue. I need to calculate the Average YTD value for each KPI on a monthly basis starting from 01 July 2025 till date Please refer to the data extraction. Please can you help with creating a dax formula? To create the formule, should I use the Calculated column option?

KPIMonthMonth ActualYTD 
Operations response and readiness complianceMar-25100  
5 Year plan complianceMar-25107  
Maintenance Workshop ComplianceMar-2595.36  
Recordable CasesMar-25100  
EBS Health indexMar-25100  
CFC vs budgetMar-250  
Capital Budget ManagementMar-25100  
Performance against SHE training matrix:Mar-2563  
5 Year plan complianceMar-25107  
Works Emergency Centre availabilityMar-25100  
Fire breaks Mar-25100  
Fire Water MonitoringMar-250  
Operations response and readiness complianceMar-25100  
Availability of Training InterventionsMar-2599  

Dear Stephen Tao,
Thanks for the PBIX file. It was an excellent learning for me as I faced the same issue. However, when I changed the visual to show the Monthly and YTD ATT under the same graphic, the YTD value changed to the Monthly value due to the changes in the context, as shown in the screenshot below. Here is the link to the same PBIX file with the new visual on the next page - It would be great if you could help me with what to change in the YTD measure in the contemporary context. The PBIX File is attached. Thanks. 

AzizQuazi_0-1694914363797.png

 

Hi Stephen Tao,
Thanks for your PBIX file to explain this. I am having the same proplem but this solution is not working for my data model - not sure where I am doing wrong. I wanted to attach the PBIX file and an excel file to show what I want but looks like I cannot attach any file - any idea why I cannot attach any file?

 

Anyway, I have a transaction table and also a date table in my mdel and I have created the foowing measures:

1. 

Total Value = SUM('Transaction Data'[USD])
2. 
_ACT_MTD Average Active Agents = CALCULATE([Total Value], 'Item'[Item] = "Average Active Agents")
3. 
_ACT_YTD Average Active Agents = CALCULATE([_ACT_MTD Average Active Agents], DATESYTD('Date'[Date]))
4. Solotion 1 to calculate average
__Solution_StephenTao = (AVERAGEX(FILTER(ALLSELECTED('Date'),[Year]=MAX('Date'[Year])&&[Month NO]<=MAX('Date'[Month NO])),[_ACT_YTD Average Active Agents]))
5. Solution 2 
   _Solution_Greg =
  VAR __MaxDate = MAX('Date'[Date])
  VAR __Year = YEAR(__MaxDate)
  VAR __Table = SUMMARIZE(FILTER('Date', YEAR([Date]) = __Year && [Date] <= __MaxDate),'Date'[Month NO],"__MonthlyAtt",[_ACT_YTD Average Active Agents])
RETURN
  AVERAGEX(__Table, [__MonthlyAtt])
 I am getting the following report - average calculatrion is not showing the right value:
AzizQuazi_3-1694329001390.png

The Feb vaue should be 13,101 + 13,901 = 27,002 / 2 = 13,501

The March value should be 13,101 + 13,901 + 17,656 = 44,658 / 3 = 14,884
Would you be able to help where I am going wong? Thanks.

 

@Greg_Deckler , you may like to help also how to write variables in this case - I tried too abve but somehow not getting the expected result. 

 

Appreciate help from the community. Thanks.

 

Rgds...Aziz

@Anonymous and @Greg_Deckler 

here is another screensht - more clearer 

AzizQuazi_4-1694329500091.png

 

 

@Greg_Deckler ,

 

Basically, the The Table variable is generating an empty table as below:

AzizQuazi_5-1694330182395.png

 

 

Here is the link to the PBIX file - hope you can access it:

https://1drv.ms/u/s!AgFUe-XGc3QMg9ML54it-XuUgMF8fQ?e=cAD1JJ
and an excel example file Troubleshoot Averge.xlsx

@Anonymous and @Greg_Deckler 

Hi @Anonymous and @Greg_Deckler 

Finally, I have managed this:

__YTD Average =
CALCULATE(
    AVERAGEX(    
        SUMMARIZE('Date',
    'Date'[Year], 'Date'[Month NO]),
    [_ACT_YTD Average Active Agents]), FILTER(ALLSELECTED('Date'), 'Date'[Year] = MAX('Date'[Year]) && 'Date'[Month NO] <=MAX('Date'[Month NO])))

Yeah! This one works for me as well!

Greg_Deckler
Community Champion
Community Champion

@mfp32 Maybe:

 

YTD Measure =
  VAR __MaxDate = MAX([Date])
  VAR __Year = YEAR(__MaxDate)
  VAR __Table = SUMMARIZE(FILTER('Table', YEAR([Date]) = __Year && [Date] <= __MaxDate),[Month],"__MonthlyAtt",[MONTHLY ATT])
RETURN
  AVERAGEX(__Table, [__MonthlyAtt])

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.