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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Rolling average when you don't have full date

Hi

I've trying to calculate the 3,6,9 months rolling average for my data. The challenge I have is that transaction dates are all dated to be 1st of each month. To elaborate more, my data looks like the below. I was wondering how can I calculate the rolling averages in such condition? The sample data in this link

Thanks in advance

 

DateCustomerQTY
1-Jan-21A200
1-Jan-21B300
1-Jan-21C400
1-Jan-21D500
1-Jan-21C100
1-Jan-21B100
1-Jan-21A200
1-Jan-21C300
1-Jan-21D500
1-Jan-21D100
1-Jan-21C300
1-Feb-21A700
1-Feb-21B600
1-Feb-21D150
1-Feb-21A250
7 REPLIES 7
tackytechtom
Super User
Super User

Hi @Anonymous ,

 

We need to remove filters from the context because otherwise the date filters to calculate the rolling x months will not be able to kick in. You could have removed all Filters by using ALL ( ), but then the rolling window would not have been applied properly when doing groupings on customer level. I assumed, that you would have liked to still be able to do such analysis. Hence, I just removed all filters except the one for customers. Another possible way could have been to explicitly remove the filter from dates, like this:

 

TomsRolling3MonthMeasureWithoutAllExcept = 
CALCULATE (
    AVERAGE (Table[QTY] ),
    REMOVEFILTERS ( Table[Date] ),
    DATESINPERIOD (
        'date'[Dates],
        EOMONTH ( LASTDATE ( Table[Date] ), 0),
        -3,
        MONTH
    )
)

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @Anonymous ,

 

You are right, I did not read your query properly. I'll update the response above. 🙂

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @Anonymous ,

 

How about this:

tomfox_0-1647114703747.png

 

 

Here the code for the measures:

TomsRolling3MonthMeasure = 
CALCULATE (
    AVERAGE (Table[QTY] ),
    ALLEXCEPT ( 'Table', Table[Customer] ),
    DATESINPERIOD (
        'date'[Dates],
        EOMONTH ( LASTDATE ( Table[Date] ), 0),
        -3,
        MONTH
    )
)
TomsRolling6MonthMeasure = 
CALCULATE (
    AVERAGE (Table[QTY] ),
    ALLEXCEPT ( 'Table', Table[Customer] ),
    DATESINPERIOD (
        'date'[Dates],
        EOMONTH ( LASTDATE ( Table[Date] ), 0),
        -6,
        MONTH
    )
)
TomsRolling9MonthMeasure = 
CALCULATE (
    AVERAGE (Table[QTY] ),
    ALLEXCEPT ( 'Table', Table[Customer] ),
    DATESINPERIOD (
        'date'[Dates],
        EOMONTH ( LASTDATE ( Table[Date] ), 0),
        -9,
        MONTH
    )
)

 

Note, it is important to have a gapless date dimension in place.

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

another question

From what I see, I require to create dates table. Which is fine.

May I know why I need to exclude the customer from the context filter?:

ALLEXCEPT ( 'Table', Table[Customer] )

On another note, I don't want the average per customer, but per month. I'll add a filter for customers (Slicer)

Anonymous
Not applicable

thanks @tackytechtom 

For average, shouldn't the DAX use Averagex/average instead of Sum?

CALCULATE (
    AVERAGE (Table[QTY] ),
    ALLEXCEPT ( 'Table', Table[Customer] ),
    DATESINPERIOD (
        'date'[Dates],
        EOMONTH ( LASTDATE ( Table[Date] ), 0),
        -9,
        MONTH
    )
)
Anonymous
Not applicable

@tackytechtom 

Something seems to be not right.

The 3 months and 6 months rolling average is the same.

also, the rolling average doesn't look right. 3 months rolling average on April-2019 should be

I think the fact that all transactions being on 1st of each month is contributing to this and it requires special processing.

YJAMOUS_0-1647119780633.png

The right values for example for 2019

 

YJAMOUS_1-1647120123324.png

 

 

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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