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
Anonymous
Not applicable

DAX to get moving average/sum with month without data

Hi there!

 

I did some searches over the PBI Community but I didn't anything how can I calculate moving average/sum with certain months with no data.

I need something like as below:

 

DateSum of events MoSum of events MovAvg 6 Mo
01-03-202011
01-04-2020zero events (no data)1
01-05-202023
01-06-2020zero events (no data)3
01-07-202014
01-08-2020610
01-09-2020211

 

Note: the blue line above just show you an example that I need for the next rows.

 

I am using this DAX:

 

Events 6 MO =
AVERAGEX(
DATESINPERIOD( dCalendario[Data], LASTDATE( dCalendario[Data] ), -5, MONTH ),
[Sum of Events (All)])
 
... with this chart result:
 
Capture.PNG

 

I appreciate your help with this matter.

 

 

 

2 ACCEPTED SOLUTIONS
vivran22
Community Champion
Community Champion

Hello @Anonymous 

 

Is this what you are looking for?

 

image.png

If yes, then you may use the following measure:

Runnning Sum = 
VAR _CurrentDate = MAX(ftCalendar[Date])
VAR  _StartDate = EOMONTH(_CurrentDate,-7)+1
VAR _Filter = 
    FILTER(
        All(ftCalendar[Date]),
            ftCalendar[Date] >= _StartDate
                && ftCalendar[Date] <=_CurrentDate
    )
VAR _Sum = 
    CALCULATE(SUM('Table'[Sum of events Mo]),_Filter)
RETURN
_Sum

 

If not, then please share more details in terms of expected output.

 

Cheers!
Vivek

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

View solution in original post

v-robertq-msft
Community Support
Community Support

Hello @Anonymous 

According to the sample table you gave,I think that the [Sum of events MovAvg 6 Mo] value of the blue line should be 12,you should check if you enter the wrong value. if it's 12,you can try the following measure:

 

Events 6 MO =
CALCULATE
(SUM('Table'[Sum of events Mo])
,FILTER(ALLSELECTED('Table')
,'Table'[Date]<=MAX('Table'[Date])))

 

 

and you can get the output chart like this:

v-robertq-msft_0-1601435737810.png

 

If not,please share more details to get your expected output.

 

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

Best Regards,

Robert Qin

View solution in original post

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hello @Anonymous 

According to the sample table you gave,I think that the [Sum of events MovAvg 6 Mo] value of the blue line should be 12,you should check if you enter the wrong value. if it's 12,you can try the following measure:

 

Events 6 MO =
CALCULATE
(SUM('Table'[Sum of events Mo])
,FILTER(ALLSELECTED('Table')
,'Table'[Date]<=MAX('Table'[Date])))

 

 

and you can get the output chart like this:

v-robertq-msft_0-1601435737810.png

 

If not,please share more details to get your expected output.

 

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

Best Regards,

Robert Qin

Ashish_Mathur
Super User
Super User

Hi,

Try this measure

=calculate([Sum of Events (All)],datesbetween(dCalendario[Data],edate(min(dCalendario[Data]),-5),max(dCalendario[Data])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
vivran22
Community Champion
Community Champion

Hello @Anonymous 

 

Is this what you are looking for?

 

image.png

If yes, then you may use the following measure:

Runnning Sum = 
VAR _CurrentDate = MAX(ftCalendar[Date])
VAR  _StartDate = EOMONTH(_CurrentDate,-7)+1
VAR _Filter = 
    FILTER(
        All(ftCalendar[Date]),
            ftCalendar[Date] >= _StartDate
                && ftCalendar[Date] <=_CurrentDate
    )
VAR _Sum = 
    CALCULATE(SUM('Table'[Sum of events Mo]),_Filter)
RETURN
_Sum

 

If not, then please share more details in terms of expected output.

 

Cheers!
Vivek

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

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.