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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
MaximB
Regular Visitor

How to calculate the average for each month from the beginning of the year?

Dear colleagues,

I can’t solve this problem, how to calculate the average from the beginning of the year for each month of this year and repeat this procedure for each next year?

For example I made a table in excel:

Screenshot 2023-09-22 at 17.36.20.png

I try do it by DATESYTD, and with SUMX it works fine, but if I change SUMX in AVERAGEX, then I get a wrong values.

1 ACCEPTED SOLUTION

Hi @MaximB 

It appears to me that you want an average based on a YTD total of monthly totals.
If that is the case, maybe try someting like this...

 

 

Monthly Average = 
VAR _Yr = SELECTEDVALUE( 'Date'[Year] )
VAR _Mon = SELECTEDVALUE( 'Date'[MonthNo] )
VAR _Table =
    FILTER(
        SUMMARIZE(
            ALL( 'Date' ),
            'Date'[Year],
            'Date'[MonthNo],
            "@Total", SUM( 'Outstanding'[Outstanding] )
        ),
        'Date'[Year] = _Yr
			&& 'Date'[MonthNo] <= _Mon
    )
VAR _Total =
	SUMX(
		_Table,
		[@Total]
	)
VAR _Count =
	COUNTAX(
		_Table,
		[MonthNo]
	)
VAR _Average =
	DIVIDE(
		_Total,
		_Count
	)
RETURN
	IF( NOT ISBLANK( SUM( 'Outstanding'[Outstanding] ) ), _Average )

 

 

Monthly Averages - try 2.pbix



Proud to be a Super User!

daxformatter.com makes life EASIER!

View solution in original post

7 REPLIES 7
gmsamborn
Super User
Super User

Hi @MaximB 

Would something like this help?

 

Monthly Average = 
	AVERAGEX(
		FILTER(
			SUMMARIZE(
				'Date',
				'Date'[Year],
				'Date'[Month],
				"@Total", SUM( 'Outstanding'[outst] )
			),
			'Date'[Year] = SELECTEDVALUE( 'Date'[Year] )
		),
		[@Total]
	)

 

Monthly Averages.pbix



Proud to be a Super User!

daxformatter.com makes life EASIER!

Hi @gmsamborn ,
thanks for your time

I tried to use your, measure and got a not entirely correct result, or rather just the sumScreenshot 2023-09-25 at 18.22.54.png

 

 

 

 

 

Tried to work with your measure a little: 
Monthly Average = AVERAGEX( FILTER( SUMMARIZE( 'Data', 'Data'[Year], 'Data'[Month], "@Total", SUMX(Data,Data[Outstanding]) ), 'Data'[Year] = SELECTEDVALUE( 'Data'[Year] ) ), [@Total] )

Hi @MaximB 

I think the main difference might be that you don't appear to be using a date table as your modified measure shows.



Proud to be a Super User!

daxformatter.com makes life EASIER!
lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Hi @lbendlin ,
I prepared the expamle table with 4 different date:

DateProductProv_typeOutstanding
30.11.2022A15
30.11.2022B110
30.11.2022C13
30.11.2022A24
30.11.2022B235
30.11.2022C262
30.11.2022A326
30.11.2022B323
30.11.2022C314
31.12.2022A112
31.12.2022B1312
31.12.2022C13
31.12.2022A2412
31.12.2022B235
31.12.2022C2512
31.12.2022A3865
31.12.2022B368
31.12.2022C3568
31.01.2023A136
31.01.2023B110
31.01.2023C1346
31.01.2023A2466
31.01.2023B2756
31.01.2023C2385
31.01.2023A3346
31.01.2023B323
31.01.2023C3346
28.02.2023A15
28.02.2023B134
28.02.2023C163
28.02.2023A2634
28.02.2023B235
28.02.2023C262
28.02.2023A396
28.02.2023B3967
28.02.2023C3678


And assume reuslt in the table under pivot:

Screenshot 2023-09-25 at 18.55.47.png

Hi @MaximB 

It appears to me that you want an average based on a YTD total of monthly totals.
If that is the case, maybe try someting like this...

 

 

Monthly Average = 
VAR _Yr = SELECTEDVALUE( 'Date'[Year] )
VAR _Mon = SELECTEDVALUE( 'Date'[MonthNo] )
VAR _Table =
    FILTER(
        SUMMARIZE(
            ALL( 'Date' ),
            'Date'[Year],
            'Date'[MonthNo],
            "@Total", SUM( 'Outstanding'[Outstanding] )
        ),
        'Date'[Year] = _Yr
			&& 'Date'[MonthNo] <= _Mon
    )
VAR _Total =
	SUMX(
		_Table,
		[@Total]
	)
VAR _Count =
	COUNTAX(
		_Table,
		[MonthNo]
	)
VAR _Average =
	DIVIDE(
		_Total,
		_Count
	)
RETURN
	IF( NOT ISBLANK( SUM( 'Outstanding'[Outstanding] ) ), _Average )

 

 

Monthly Averages - try 2.pbix



Proud to be a Super User!

daxformatter.com makes life EASIER!

@gmsamborn , thank you very much, this is what I need. I transferred the formula to my real data and now everything works. Thank you again, I have been struggling with this problem for several days

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors