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

Rolling 12 month average

Dear all,

I know there are same topics posted, but I'm still confusing. Please help.

I'm trying to write a formula that calculates the average of the rolling 12-month date difference. 

The date difference is calculated as below:

datediff = DATEDIFF('Time to NC priority determination 12m'[NC Date Opened],'Time to NC priority determination 12m'[NC Initial Priority On],DAY)
NC Date Opened and NC Initial Priority On are the only two date columns, ranging from  01/01/2016 to 08/16/2022. I also have a calendar table, and I've set up a relationship. 
Here is my formula for the rolling avg:
Average of datediff rolling average =
CALCULATE(DATEDIFF(VALUES('Time to NC priority determination 12m'[NC Date Opened]),VALUES('Time to NC priority determination 12m'[NC Initial Priority On]),DAY),
DATESINPERIOD('Date Table'[Date],
       LASTDATE('Date Table'[Date]), 12, MONTH))
/
CALCULATE(DISTINCTCOUNT('Date Table'[Date]),
DATESINPERIOD('Date Table'[Date],
       LASTDATE('Date Table'[Date]), 12, MONTH))
This returns nothing, I'm not familiar with using a calendar table in the formula. Please help me.
Thanks in advance
5 REPLIES 5
Fowmy
Super User
Super User

@Anonymous 

First, add a calculated column to your table to calculate the Date Difference as follows

Fowmy_0-1660678823814.png
Create a relationship between the Dates[Date] and Time to NC priority determination 12m'[NC Date Opened]


Create the following measure:

Avg Rolling 12 Months = 
CALCULATE(
    AVERAGE( 'Time to NC priority determination 12m'[datediff] ),
    DATESINPERIOD( 'Dates'[Date] , MAX( 'Dates'[Date] ) , -12 , MONTH )
)

Result

Fowmy_1-1660678958212.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Hi @Fowmy, I did what you mentioned above, but it still returns blank.
I don't know why that happened, my Date Table has a larger range than NC Date Opened and NC Initial Priority On (There are some duplicates in NC Date Opened and NC Initial Priority On). I'm not sure if this is the reason of return blank.

Lucasw_0-1660738363828.png

 

Syndicate_Admin
Administrator
Administrator

Total Cumulative Customer Cost Mobile Period =
Total Customer Cost Accumulated in the period between the last 12 months, including current month (e.g. Current month July, Calculation made since July and August of last year)
CALCULATE(
[Total to be calculated],
DATESINPERIOD(
Dates[Date], //name of your date table and date column
LASTDATE(Dates[Date]),
-12,
MONTH
)
)

Anonymous
Not applicable

Hi @Syndicate_Admin, I have tried the code you mentioned. But I don't know why it returns me blank

Greg_Deckler
Super User
Super User

@Anonymous First piece of advice, don't use TI functions. 2nd piece of advice:

Rolling Months - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.