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
billuran
Helper I
Helper I

Average Age of Accounts by Month

Hello,  For simplicity, I have a table

AcctID Opened_DateClosed _Date

1

1/8/20202/5/2020
21/9/20201/31/2020
32/1/20203/15/2020

 

I need to caluclate the age of the account at the beginning of every month of 2020

Result I need for my 100,000s records

 

DateAvg Age at Date (Logic for bi community help)
1/1/2020       0(None are Open then)
2/1/2020       23.5(Avg of 1 and 2 because both are open at 2/1)
3/1/2020       29 (BC 1 and 2 are closed and Account 3 is open and 29 days old)
4/1/2020       0(bc account 3 has closed by 4/1)

 

1 ACCEPTED SOLUTION

Hi @billuran ,

 

We have a little confused about your issue, what the total avg age?

Is it the Total day of the current month divided by the ID of the current month?

For example, the 2020/2/1 has two ID, the total day is 23 + 24 = 47. So the result is 47 / 2 = 23.5

If yes, you can refer the following steps.

 

1. Create a calculate column named Month date.

 

Month Date = CALCULATE(MIN('Date table'[Date]),FILTER('Date table','Date table'[Date]>'Table'[Opened_Date]))

 

av1.jpg

 

2. Then create the difference days column.

 

difference = DATEDIFF('Table'[Opened_Date],'Table'[Month Date],DAY)

 

av2.jpg

 

3. Then we can create the Total measure and result measure.

 

Total = SUM('Table'[difference])+0

 

Measure = 
var _amount = DISTINCTCOUNT('Table'[AcctID])
return
DIVIDE([Total],_amount)

 

av3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

View solution in original post

6 REPLIES 6
v-zhenbw-msft
Community Support
Community Support

Hi @billuran ,

 

We can create a calculate column and a relationship, then create a measure to meet your requirement.

 

1. Create a calculate column that gets the min month date.

 

Month Date = CALCULATE(MIN('Date table'[Date]),FILTER('Date table','Date table'[Date]>'Table'[ Opened_Date]))

 

Av1.jpg

 

2. We can create a one-to-many relationship between table and Date table.

 

Av2.jpg

 

3. Then we can create a measure and the result like this,

 

Measure = AVERAGEX('Table',DATEDIFF('Table'[ Opened_Date],'Table'[Month Date],DAY))+0

 

Av3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

The formula seems to only show the avg age between Month Date, I woudl like the total avg age from Opened to the Month Date

Hi @billuran ,

 

We have a little confused about your issue, what the total avg age?

Is it the Total day of the current month divided by the ID of the current month?

For example, the 2020/2/1 has two ID, the total day is 23 + 24 = 47. So the result is 47 / 2 = 23.5

If yes, you can refer the following steps.

 

1. Create a calculate column named Month date.

 

Month Date = CALCULATE(MIN('Date table'[Date]),FILTER('Date table','Date table'[Date]>'Table'[Opened_Date]))

 

av1.jpg

 

2. Then create the difference days column.

 

difference = DATEDIFF('Table'[Opened_Date],'Table'[Month Date],DAY)

 

av2.jpg

 

3. Then we can create the Total measure and result measure.

 

Total = SUM('Table'[difference])+0

 

Measure = 
var _amount = DISTINCTCOUNT('Table'[AcctID])
return
DIVIDE([Total],_amount)

 

av3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

Hi @billuran ,

 

How about the result after you follow the suggestions mentioned in my original post?

Could you please provide more details or expected result about it If it doesn't meet your requirement?

If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly.

 

Best regards,

 

Community Support Team _ zhenbw

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

Greg_Deckler
Super User
Super User

@billuran - Perhaps:

Measure =
  AVERAGEX(FILTER('Table',[Opened_Date]>MAX([Date])),([Closed Date] - [Opened Date])*1.)


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.