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.
Hello everyone. I have a question on DAX to calculate moving average. Can I do moving average on 2 measures: 1 measure is sum of historical data calculation, the other measure is sum of forecast calculation? I know how to do moving average on them individually, but I'd like to combine them and do the moving average on both historical and forecast together.
Say I have some sales data and 2 measures such as below. The yellow highlighted, 3 Days MA Combined is the result I'm looking for. Any hint or advice is appreciated.
Solved! Go to Solution.
Hi,
I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
I hope this can provide some ideas on how to create a solution for your data model.
Moving avg 3days: =
VAR _currentdate =
MAX ( 'Calendar'[Date] )
VAR _threedaysbefore = _currentdate - 2
VAR _condition =
CALCULATE ( [Sales combine measure:], 'Calendar'[Date] = _threedaysbefore )
<> BLANK ()
&& [Sales combine measure:] <> BLANK ()
RETURN
AVERAGEX (
DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -3, DAY ),
[Sales combine measure:]
)
* DIVIDE ( _condition, _condition )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi @DataSundowner,
Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.
If these also don't help, please share more detailed information to help us clarify your scenario to test.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng
Hi,
I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
I hope this can provide some ideas on how to create a solution for your data model.
Moving avg 3days: =
VAR _currentdate =
MAX ( 'Calendar'[Date] )
VAR _threedaysbefore = _currentdate - 2
VAR _condition =
CALCULATE ( [Sales combine measure:], 'Calendar'[Date] = _threedaysbefore )
<> BLANK ()
&& [Sales combine measure:] <> BLANK ()
RETURN
AVERAGEX (
DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -3, DAY ),
[Sales combine measure:]
)
* DIVIDE ( _condition, _condition )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Thank you @Jihwan_Kim. The dax didn't work in my model, but your idea of adding up historical and forecast to combine them helped me a lot and and I figured out the rest.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
97 | |
75 | |
65 | |
53 |
User | Count |
---|---|
144 | |
103 | |
98 | |
85 | |
64 |