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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
FireFighter1017
Advocate III
Advocate III

DAX EMA Attempt

I was able to create a couple of measures to obtain it:

 

First you need a simple moving average for your 1st period.  I'm using a 8 period SMA here:

 

When used in the EMA DAX, it will pickup the right SMA (see measure [Reactive Hours SMA8] in variable "_EMAW8".

Now here's how it all comes together:

 

 

Reactive Hours EMA8 = 
	var _lastDate = CALCULATE(MAX('Calendar'[WeekEndDate]), FILTER('Calendar', 'Calendar'[WeekEndDate]<today()))
	var _N = 8
	var _smoothFactor = 2 / (_N + 1)
	
	var _EMAW8 = 
		var _days = _N * 7
	    return CALCULATE(
	        [Reactive Hours SMA8] + _smoothFactor * ([Sum of Reactive Work] - [Reactive Hours SMA8]),
	        FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    )
    
    var _EMAW7 = 
		var _days = (_N - 1) * 7
		var _prevEMA = _EMAW8
	    return 
	    	CALCULATE(
	        	_prevEMA + _smoothFactor * ( [Sum of Reactive Work] - _prevEMA ),
	        	FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    	)
	
	var _EMAW6 = 
		var _days = (_N - 2 ) * 7
		var _prevEMA = _EMAW7
	    return 
	    	CALCULATE(
	        	_prevEMA + _smoothFactor * ( [Sum of Reactive Work] - _prevEMA ),
	        	FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    	)
	
	var _EMAW5 = 
		var _days = (_N - 3 ) * 7
		var _prevEMA = _EMAW6
	    return 
	    	CALCULATE(
	        	_prevEMA + _smoothFactor * ( [Sum of Reactive Work] - _prevEMA ),
	        	FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    	)
	    	
	var _EMAW4 =
		var _days = (_N - 4 ) * 7
		var _prevEMA = _EMAW5
	    return 
	    	CALCULATE(
	        	_prevEMA + _smoothFactor * ( [Sum of Reactive Work] - _prevEMA ),
	        	FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    	)
	
	var _EMAW3 = 
		var _days = (_N - 5 ) * 7
		var _prevEMA = _EMAW4
	    return 
	    	CALCULATE(
	        	_prevEMA + _smoothFactor * ( [Sum of Reactive Work] - _prevEMA ),
	        	FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    	)
	
	var _EMAW2 = 
		var _days = (_N - 6 ) * 7
		var _prevEMA = _EMAW3
	    return 
	    	CALCULATE(
	        	_prevEMA + _smoothFactor * ( [Sum of Reactive Work] - _prevEMA ),
	        	FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    	)
	
	var _EMAW1 = 
		var _days = (_N - 7 ) * 7
		var _prevEMA = _EMAW2
	    return 
	    	CALCULATE(
	        	_prevEMA + _smoothFactor * ( [Sum of Reactive Work] - _prevEMA ),
	        	FILTER(ALL('Calendar'[WeekEndDate]), 'Calendar'[WeekEndDate] = _lastDate - _days)
	    	)

	return
        _EMAW1

 

 

Note that "_lastDate" variable return the week end date from last week with any date filter applied, so that wehn you put the measure in a line chart with a date axis, it will calculate the EMA for each date.

 

 

var _lastDate = CALCULATE(MAX('Calendar'[WeekEndDate]), FILTER('Calendar', 'Calendar'[WeekEndDate] < today()))

 

 

 Then every "_EMAWx" variable will calculate the EMA from the 8th week from now up to last week.

 

Now I did get differences from an Excel Spreadsheet calculation of the same data.  So I'm not entirely sure if it's accurate.  Any feedback woudl be appreciated

2 REPLIES 2
FireFighter1017
Advocate III
Advocate III

I had to apply it to a more generic model to avoid any legal problems with sharing the actual model I was working with.

I have thrown a little bonus there.  It also includes MACD formulas I am currently using to measure trend momentum.

Here's a link to the file: PowerBIDAXexamples/DAX EMA example.pbix at main · FireFighter1017/PowerBIDAXexamples (github.com)

 

Let me know if you are able to get this one or not.

Anonymous
Not applicable

Hi @FireFighter1017 ,

Would you please provide some sample data (with sensitive information removed) and post the expected output?
Thanks in advance.

How to Get Your Question Answered Quickly

How to provide sample data in the Power BI Forum

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.